Do your file servers always seem to be short on disk space? To help plan storage requirements, you can write PerlDriveSpace.pl, a script that produces an intranet report displaying domainwide disk utilization and trend information. You can write this script with Perl.
PerlDriveSpace.pl demonstrates the functionality of both the Perl language and the AdminMisc extension. This script parses an input text file called serverlist.txt and creates the DiskStatsLog.html report. As Screen 1 shows, this report includes
- A department logo and current date header
- Hyperlinks to previous versions of the report
- table displaying the percentage of space utilized, gigabytes of space free, gigabytes of space used, and gigabytes of total drive space
The script renames recent versions of the DiskStatsLog.html report, allowing hyperlink navigation to the current report and 10 archived reports. The script includes some Error-Correcting Code (ECC) to handle offline servers and nonexistent shares entered in serverlist.txt. In addition, the text color changes to red if the disk utilization percentage exceeds a configurable threshold.
Listing 1, page 6, contains an excerpt from PerlDriveSpace.pl. You can find the entire script on the Win32 Scripting Journal Web site. To help you follow how the Perl script works, I included comments in the code. Here are the steps to get the script working:
- Download and install Perl for Win32 and the AdminMisc extension on the NT workstation or server where the script will run. I tested this script using ActivePerl build 517, which is available from ActiveState Tool (http://www.activestate.com). The AdminMisc extension is available from Roth Consulting (http://www.roth.net/perl). Perl installs easily from a self-extracting executable. The Perl Package Manager (PPM) command to install this extension is
C:/> ppm install http://www.roth .net/perl/packages/Win32-AdminMisc .ppd
The Roth Web site has additional information about the GetDriveSpace function that the script uses. Both Web sites are excellent resources for Perl scriptwriters because they have extensive online documentation.
- Place PerlDriveSpace.pl on the server where you've installed Perl and the extension.
- Create an input text file named serverlist.txt that contains the list of servers and shares for disk utilization monitoring. (You can find an example of the serverlist.txt input file on the Win32 Scripting Journal Web site.) In one entry per line, put the server name and share name, separated by double backslashes (e.g., FILESERVER15\PUBLIC). You can include Administrative and hidden shares (e.g., C$, D$) using the same basic syntax (e.g., FILESERVER15\\C$). This powerful script lets you monitor and gather statistics on every drive on every workstation or server you administer.
- Specify the serverlist.txt location in PerlDriveSpace.pl.
- Specify the local or remote location where you're going to maintain the DiskStatsLog.html reports. You can copy these reports to the Web server in a subsequent operation or write the reports to the Web server directly. Use the upload strategy that works best in your environment.
- Specify the threshold of disk utilization (i.e., the percent of utilization at which you want the text to turn red). The threshold in PerlDriveSpace .pl is at 80 percent.
- Test the script to be sure it's working properly. Run the script from the command prompt if you want to view any error messages. Check the DiskStatsLog.html report to see whether all the shares are showing up properly. Check any shares in which an N/A appears; the server might be offline, you might have specified a CD-ROM drive, or you might have specified a nonexistent share or drive.
- Schedule the script to run at the frequency you require.