Cover by Wolfgang Barth

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 25. Determining File and Directory Sizes

For a specific example of a Perl plugin, we will look at check_du.pl.[296] It is used to determine the size of specified files or directories and to check whether the total size lies within preset thresholds. To do this, it calls the system program du:

user@linux:~$ du -cs /var/spool/var/log
26524   /var/spool
745640  /var/log
772164  total

When used with the -s option, du does not list all the individual subdirectories but just shows the total size. -c adds up individual values to reach a total size.

At the beginning, the plugin generates a new new Nagios::Plugin object with the new constructor so that it can make use of the functions of the module:

#!/usr/bin/perl -w use strict; use warnings; use FindBin; ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required