Friday, June 1, 2012

Script to generate file-system usage report

This script is developed specifically for checking the File-system usage of SAN Mounts on Linux or any UNIX flavors. 
However this can be used to check any Unix filesystem such as /var, /opt, /root etc. This script takes Access, Modified and Change Time as parameters on the specified Mount points and followed by an E-mail address. Upon execution, it will send you the resultant output of the script to the E-mail address that you specified in sorted form with the total size of matching files. In addition a copy of the script output will be stored on the path where you executed the script in the following format: Hostname-Month-Day-Year.

URL to download:

Supported platforms: Any Unix platform with Perl version 5.x or above installed.

How to use:
The syntax for executing this script is as follows:

# [-t]  [-a <value> -m <value> -c <value>]  <Mount points  separated by space>
“-t” for Total disk space
“-a” for access time
“-m” for modification time
“-c” for change time

Upon executing the above command will prompt you to enter the E-mail address to which the file-system usage report needs to be sent. Please note the switch “-t” is optional whereas the other switches “ -a, -m, -c “ are must (atleast one or more). You can give multiple filesystem pathnames separated by space but I suggest giving just one in-order to avoid confusion in sorted output; where the files will be sorted in accordance to its size.

Few Sample Syntax:
# perl -t -a 1000 /san_mount1      <-- List Files which are accessed 1000 days before.

# perl -t -c 1000 /Netapp_filer_mount2  <-- Files which are changed 1000 days before.

# perl -t -m 300  /var                <-- Files modified 300 days before in /var

# perl -t -a 500 -m 750 /u01      <-- Files which are accessed 500 days before and modified 750 days before on /u01.

# perl -t -a 365 /san_mnt1 /san_mnt2     <-- Files which are accessed 365 days before on 2 SAN mounts

How it works:
This script uses &wanted subroutine which comes along with standard Perl Module “File::Find” for traversing through all the files in a desired filesystem. For each file it finds, it checks whether it matches with the parameters supplied and if it is true, it will output the file information along with file size information.  This is a non-intrusive script, as this is equivalent to executing a ‘find’ command. 


  1. I recommend to refer this link as well:

  2. Hi Raj,

    I have one question. My requirement is generating Monthly File system usage report.script to generate df -h output to excel sheet and then i can take out stats and graphs on that data for one month.

    Any help would be appreciated.