Category Archives: Systems Administration

shell script to automate the Lucene search

Wrote my first shell script to automate the Lucene search that handles searching for this blog. Got the goods here on shell scripting and stuff here on Cron. End result: a shell script that updates the Lucene index for this blog and pipes the output of the index script to an email:

#!/bin/bash
# Script that indexes the appropriate directories
# using Lucence & Java
cd /usr/hosts/cephas.net/wwwroot/blog/
java -cp /usr/hosts/cephas.net/wwwroot/WEB-INF/lib/lucene-demos-1.2.jar:
/usr/hosts/cephas.net/wwwroot/WEB-INF/lib/lucene-1.2.jar org.apache.lucene.demo.IndexHTML
-create -index /usr/hosts/cephas.net/wwwroot/blog/index/ .. | mail -s “LUCENE[cephas.net/blog]” aaron.s.johnson@gmail.com

wsh for windows automation

Follow up to last night’s post on wget. The wget app (in my case) needs to run every couple hours during the day. Windows 2000 and higher has a built task scheduler which I could (and will) use to schedule the execution of the task, but to do this I’d have to type some kludgy command line arguments AND I’d have to have administrator access to the machine in order to change any of the properties of the task. There must be a better way… enter Windows Script files(.wsf), which is “.. a text document containing Extensible Markup Language (XML) code, incorporates several features that offer you increased scripting flexibility. (from MSDN). It’s kinda like ANT, except Windows specific.

My download wget script eventually looks like this:

http://someserver.com/myxmlpacket2.xml.gz

FileName.xml.gz

http://someserver.com/myxmlpacket.xml.gz

theNameofMyFile.xml.gz

Couple things to notice: a) a wsf is valid xml, b) you can run multiple jobs in one file, and c) you can reuse your existing VBS scripts. So now, seeing my wsf file, how would I call that using the Windows Task Scheduler? You want to run cscript.exe, which is in c:\$winnt$\system32\, so you’re run command would look like this:

C:\WINNT\system32\cscript.exe //Job:daypart c:\wget\wget.wsf

where ‘daypart’ is the name of the job within your wget.wsf file. Using WSF as a wrapper for the wget executable allows you to easily tasks to a specific jobs. Even better, you can access almost anything on a Windows system or network using VBScript/WSH, including accessing network connections, creating local applications, and managing the system registry.