Spellings Consulting

When you need IT done right.

Archive for the 'Scripts' Category

HTTP Request Script

I recently thought that I would be nice to write a VB Script that could run as a scheduled task that would attempt to login to a data-driven web site and notify me via email if there was an unsuccessful login.  I figured that this would be a good way to pro-actively be notified if a client’s website had gone down (ie: if you can’t login, something has happened to the site).

The script sends an http request with form post data in the http header and waits for the HTTP server response.  It then looks for a specific string that will only appear in the response after a successful login, such as the username or a specific greeting that appears on the landing page.  If the expected string is not found, then the Vb Script sends an email (optional) and also writes the HTTP Server response to a local file with a unique name so that a user can inspect the responses for debugging and forensic purposes.

Download the script here and use it freely as long as you do not resell it, and you don’t blame me for unexpected results.

Subdirectory Sizes Script

Ever wonder where all your hard drive space is going?  At work,we had a 1 terabyte hard drive that was quickly filling up and wanted to know where all the space was going.  Some of the directories were so large that right-clicking on them would essentially crash windows (make the explorer window nonresponseive), so another solution was needed.

 So I wrote a VB Script to do the job.  Simply place this VB Script in any directory and double-click it.  It will find the size of every subdirectory therein and create a log file listing the sizes of every subdirectory.  The script’s log file is written in HTML and displayed in Internet Explorer.  This was done to create a log flie that is easier to read.

If you’d like to use this script, feel free to download it here.  If you’d like features added to the script, please leave a comment.

Zip Script

I was recently asked to zip up tens of thousands of files in a few hundred subdirectories.  The targeted files were those whose Last Modified date was older than one year ago.  Instead of manually zipping all of these files, I started looking for a way to automate this process.  I discovered that WinZip offers a Command Line Add-on, which would be accessible via script.  The Add-on does require the pruchase of WinZip 10 Pro, which I later discovered actually has similar features built-in already.

The Script
The script I’ve written is a VB Script that also utilizes the WinZip Command Line add-on mentioned above.  I have tested the script on: Windows 2000, Windows XP Pro, and Windows 2003 Server Standard Edition 64-Bit. 

After I wrote the script to use in a specific situation, I realized that it would be useful to alter it to be used in a more generic way.  So I added some features that allow the script to be called from the command line or a batch file in a manner where the user can add arguments when they call the script to control (1) the target directory (2) the Archive Date threshold (3) the file types to be zipped.

How it Works
The script goes through all the subdirectories in a directory and compares the Last Modified Date of each file to a date specified by the user.  If the Last Modified Date is older than the specified date, then the file is added to a zip file that is named the same name as the subdirectory.  If there is no existing zip file, then one is created.  After the files are added to the zip, they are removed from the subdirectory.

You can run the script as a scheduled task, but if you do, so be sure to alter the Default values for all of the variables that control how this script selects the target directory and files.  This is clearly commented in the code, so it should be easy to find.

The script also keeps a very detailed log file about what happens every time that it runs.  It can also be configured to send an email when it complete or fails.

If you would like a copy of this script, feel free to use it, but please give creidt to the author.  You can download it here.