Real-World Scripting: Perl Script Creates a Disk Utilization Report


Do your file servers always seem to be short on disk space? To help plan storage requirements, you can write, a script that produces an intranet report displaying domainwide disk utilization and trend information. You can write this script with Perl. 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 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:

  1. 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 ( The AdminMisc extension is available from Roth Consulting ( 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

    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.

  2. Place on the server where you've installed Perl and the extension.
  3. 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.
  4. Specify the serverlist.txt location in
  5. 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.
  6. 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.
  7. 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.
  8. Schedule the script to run at the frequency you require.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.