ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok, this may not be the most elegant way, but it works...
Mail is not sent if there is nothing higher than $above. If there is, all the ones higher than $above are delivered in the same email.
Code:
#!/usr/bin/perl
$mailfrom = "whoever\@whatever.com";
$mailto = "whoever\@whatever.com";
$above = 90;
use FileHandle;
@check=`df -k`;
##### Checks for lines higher than $above
foreach (@check) {
if (m/(\d+\%)/ and $1 >=$above) {
push @New,$_;
}
}
##### If there is anything found, send mail
if (@New) {
$mail = new FileHandle;
$mail->open("| /usr/sbin/sendmail -t") || die "Cannot open: $!";
$mail->print("From: $mailfrom\n");
$mail->print("To: $mailto\n");
$mail->print("Subject: Disk space is low!\n\n");
$mail->print(@New, "\n");
$mail->close();
}
The code in post #16 does not send an email if none of the partitions are over the % your looking for.
But ...what if you want the entire df output and the server name if any partition is over the %? That is my situation but I don't know how to modify this code to make it so.
a little help please.
Thanks.
I have just realized that the script i wrote is not complete. If NONE of my partitions are over 90%, it will send me a blank body mail message. Hmmm, I tried using if statements here and there but it fails. Can anyone show me the right direction...im such a noob. THanks...
-twantrd
how did you use if statements here and there?
one way is the check whether there is anything in @warn before you send the email, like whether its length is greater than 0?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.