Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: disk check using perl

by moklevat (Priest)
on Dec 14, 2007 at 16:36 UTC ( #657076=note: print w/replies, xml ) Need Help??

in reply to disk check using perl

Rather than trying to parse the the df output yourself, you may find it easier to work with the Filesys::Df module.

To send an e-mail to yourself, you should look into one of the many modules that exist to make this easy. I like MIME::Lite.

Update: Here is some (untested) code to work with. You will have to modify the email message with your e-mail addresses, and you might want to tweak the language of the Subject and Data (body text) to suit your style. Otherwise, the script reads the percent disk used from / and e-mails you if the percentage if greater than a threshold amount (in this case 90%)

#!/usr/bin/perl use strict; use warnings; use Filesys::Df; use MIME::Lite; my $disk_info = df("/"); my $threshold = 90; my $disk_percent; if (defined($disk_info)){ my $disk_percent = $disk_info->{per}; } if ($disk_percent > $threshold) { my $message = MIME::Lite->new ( From =>'', To =>'', Cc =>'', Subject =>'ALERT: Im in ur disk usin ur inodes!', Data => "It appears that the disk use threshold is + approaching the limit defined in your helpful script. You currently +have $disk_percent percent used. Perhaps you should check on this." ); $message -> send ; }

Replies are listed 'Best First'.
Re^2: disk check using perl
by steadybompipi (Initiate) on Dec 14, 2007 at 17:35 UTC
    seem like my perl version is old in my box. got the below command when i first run. Can't locate in @INC (@INC contains: /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at line 4. BEGIN failed--compilation aborted at line 4. hence i delete the user warnings; but it still show me some error. Can't locate Filesys/ in @INC (@INC contains: /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at line 10 kindly advice~

      use warnings; can safely be removed. It's useful during development and debugging but shouldn't much change the operation of a program. As an alternative, you can add '-w' to the shebang line as in:

      #!/usr/bin/perl -w
      90% of every Perl application is already written.
      perl can't find the module in @INC !
      You must install Filesys::Df module from with cpan shell or download the source and install it.
      include for example with use lib 'path_to_your_pm_lib';
      if you don't have the cpan shell :
      Enter from the shell command line
      perl -MCPAN -e 'install Filesys::Df'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://657076]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2017-09-24 07:09 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.