LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2004, 06:35 PM   #16
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31

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();
}
 
Old 10-01-2004, 12:42 AM   #17
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Original Poster
Rep: Reputation: 52
Hey thanks!

-twantrd
 
Old 05-31-2006, 12:50 AM   #18
deepspatil
LQ Newbie
 
Registered: May 2006
Posts: 1

Rep: Reputation: 0
low disk space script problem

I am also facing the same problem with the script. If NONE of my partitions are over 90%, it will send me a blank body mail message.

If anybody found the solution on this please update us.
 
Old 09-05-2006, 09:14 AM   #19
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Did you try the code in post #16? It appears to take care of that problem. (I'm trying it now ....if it does not take care of it I'll post an update.)
 
Old 09-05-2006, 10:01 AM   #20
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
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.
 
Old 09-05-2006, 10:29 AM   #21
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by twantrd
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
out of disk space... snoply Linux - Enterprise 6 05-06-2005 08:56 AM
How to get rid of the begining and end space of a string for PERL?? cqmyg5 Slackware 2 04-28-2005 04:34 PM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 03:58 PM
Where is all my disk space going? Baryonic Being Linux - General 6 10-13-2004 07:57 AM
Disk space wastage 73 GB Hard disk rajgopalhg Linux - Hardware 2 10-18-2002 03:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration