Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 =>'diskwatcher@yourcomputer.com', To =>'fixitguy@othercomputer.com', Cc =>'someonewhocares@somedomain.com', 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 ; }


Comment on Re: disk check using perl
Download Code
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 warnings.pm 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 test2.pl line 4. BEGIN failed--compilation aborted at test2.pl line 4. hence i delete the user warnings; but it still show me some error. Can't locate Filesys/Df.pm 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 test2.pl 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.
      dragonchild
      perl can't find the module in @INC !
      You must install Filesys::Df module from cpan.org with cpan shell or download the source and install it.
      or
      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'
      HTH,
      PooLPi

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://657076]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2015-07-08 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls