Lesson of this article is: Script It!
I will also show an in depth example of a sheduled script which will zip/rotate/delete/move/copy you logfiles. This is a typical task everyone with a webserver would automate/script because you want to save your logfiles for statistics and to track ‘bad’ visitors while zipping them reduces it’s size approximately 25 times. So a 100MB logile will only be 4MB.

You can much better script the tasks you do often than doing it by hand all the time.
Advantages are:

  • No human mistakes any more
  • Scheduled scripts always run on time, even when you’re on holiday
  • Schedule scripts at night to save server resources and minimize impact on other systems
  • Last but not least: It saves you a lot of time which you can spend on scripting other things ;)

Before scripting tasks i advise you to do the tasks manually a few times, then you exactly know which steps you have to do and which are always the same, you have more feeling with the task now.

The Example
Everyone with a webserver (especially Microsoft IIS) knows the work which comes along with the IIS Logfiles.
I found an easy to schedule script which will let you automate the process: waRmZip.
waRmZip is a Windows Script (WSF / VBScript) which let you compress, move and delete your logfiles, it does not include a compress utility like PkZip or Winzip, that’s why we use a free and very good utility: 7-zip (the command-line version).

Click on the Start button -> Click Run -> Type “tasks
Click Add a new scheduled task -> Click Browse and enter:

C:\Windows\System32\cscript.exe "C:\Program Files\7-Zip\waRmZip.wsf" "C:\WINDOWS\system32 LogFiles" /fo:".log" /r /ca:366 /cp:"C:\Program Files\7-Zip\7za.exe" /cpp:"a -tzip -mx9 OLD\$out $in" /q 

This let cscript.exe execute the waRmZip.wdf script with the following parameters:

“C:\WINDOWS\system32\LogFiles” is the recursive path from where to start
/fo:”.log” It mean that we only do things with “.log” files so we will never harm other files
/r It means the main directory and all sub-directories (recursive)
/ca:366 It means we compress the *.log files after 366 days (since our statistic program need logfiles of the past year)
/cp:”C:\Program Files\7-Zip\7za.exe” We use 7-Zip as the zip utility so give the location to it here
/cpp:”a -tzip -mx9 OLD\$out $in” Give the extra command line paramters for 7Zip, we use high compression and \OLD\ as our output path
/q Means the wArmZip script will give no output during execution

For Start in location we use: “C:\Program Files\7-Zip” (with quotes)
Run the task under a user with enough rights, the current logged in user is the default. This user should have access and enough rights to read/write to all the (network)paths used in the task/script.
Click on the Schedule tab and configure when the task/script should run. We prefer to run it at 01:00 because the default for IIS is to rotate the logs daily at 00:00.

The above parameters are based on wArmZip version 1.7 (November 2005), however i found and reported a few bugs so i hope version 1.8 will follow soon.