A while back I needed a warning system for when my backups disk runs out of free space. Gathering information from various other existing scripts, I wrote a small Perl script that checks the available space and sends warning emails if this drops below a defined level.


You need to have Perl installed for the script to run. The installation/configuration steps below are Fedora/CentOS/RedHat systems, but the script should work on any Linux system via Perl.

The script requires the Filesys::DiskFree, File::Touch modules, both installable via CPAN perl -MCPAN -e shell

If you get a Can’t locate CPAN.pm in @INC … then you need to install CPAN first: yum install perl-CPAN -y

First run of CPAN will run some diagnosis test (which may take a while). It’s also a good idea to update CPAN by running the following in the prompt:
install CPAN
reload cpan

Then simply install the required Perl modules (this should be quick) with install Filesys::DiskFree File::Touch

“Installation” and configuration

This script has a couple of configurable parameters that need to be defined for it to work correctly (these are located at the beginning of the script).

$count Number of the mount points defined below
@dirs Comma separated list of mount points to monitor; eg: (“/”,”/backups”)
$work_dirs Temporary directory used by the script to store temporary data. Needs to be writeable by the user running the script.
Warning settings
$warning_level The percentage of free disk space under which the warnings are triggered; default = 10 %
$warning_interval Interval in minutes between warning emails (if level is reached); default = 10 (minutes)
$warning_remind 0 = send warning email once and only warn again when space level decreases again
1 = send warning email every “interval” minutes even if space level no longer decreased
Email settings
$to E-mail address of the recipient (this should be your email)
$from E-mail address used by the script as the sender


Finally create a cron entry to run the script (this will check free space on the configured mount points every 10 minutes):

*/10 * * * * /etc/rc.d/freespace.pl >/dev/null 2>&1


Copy-paste the code below into /etc/rc.d/freespace.pl:


Leave a Reply