Sending an email if system disk space is low


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending an email if system disk space is low
# 1  
Old 05-08-2014
Sending an email if system disk space is low

Hello i have a working script that sends me an email if system disk space is above 98%.
I would like to add an extra command to the if condition. If disk space is above 98% it would also add an output of
Code:
cd /var/log && du -sBM * |sort -n 2>&1 |grep -v -e "0M" -e "1M"

command to the email.

I'm new at scripting and couldn't figure this out Smilie

My working script:

Code:
#!/usr/bin/perl

$mailfrom = "email\@mydomain";
$mailto = "email\@mydomain";
$above = 98;

use FileHandle;

@check=`df -h | grep -vE '^Filesystem|none|cdrom'`;

##### Checks for lines higher than $above
foreach (@check) {
    if (m/(\d+\%)/ and $1 >=$above) {
	cd /var/log && du -sBM * |sort -n 2>&1 |grep -v -e "0M" -e "1M";
        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: diara.ee sda1 disk space low\n\n");
    $mail->print(@New, "\n");
    $mail->close();
}

# 2  
Old 05-08-2014
Change the email part to below
Code:
if (@New) {
    my $data = qx(cd /var/log && du -sBM * |sort -n 2>&1 |grep -v -e "0M" -e "1M");
    $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: diara.ee sda1 disk space low\n\n");
    $mail->print(@New, "\n");
    $mail->print($data, "\n");
    $mail->close();
}

This User Gave Thanks to SriniShoo For This Post:
# 3  
Old 05-08-2014
And it works Smilie
Thanks for the mastery.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate disk space usage email alert

hi all members I have a shell script to generate disk space usage email alert if threshold is more than 80 %, now the requirement changed to keep sending alert emails for every 5% incremental usage ........ Any help would be greatly appreciated. ex - 80% , 85% ,90%,95%,100% we should get an... (6 Replies)
Discussion started by: anil529
6 Replies

2. Shell Programming and Scripting

Send Disk Space Usage Status via email

Hi Guys, Is there any way I can write a script that sends DISK SPACE USAGE STATUS via email once a week? Thanks, (5 Replies)
Discussion started by: g4v1n
5 Replies

3. AIX

High Runqueue (R) LOW CPU LOW I/O Low Network Low memory usage

Hello All I have a system running AIX 61 shared uncapped partition (with 11 physical processors, 24 Virtual 72GB of Memory) . The output from NMON, vmstat show a high run queue (60+) for continous periods of time intervals, but NO paging, relatively low I/o (6000) , CPU % is 40, Low network.... (9 Replies)
Discussion started by: IL-Malti
9 Replies

4. Shell Programming and Scripting

Check and compare disk space and email it

I am very new to Linux and learning to script. This is for one of my servers at work that I have to keep track off as far as disk space and how it is used. I have tried to go line by line but little things keep chewing me up. I would appreciate any and all help or advice, and Mutt is installed on... (3 Replies)
Discussion started by: sgtjkj
3 Replies

5. Solaris

Sending email from solaris 9 system

hi i read threads for sending email to public mail ids like gmail.com, yahoo.com from solaris 9 system but i could not succeed. can some body help me out. I have tried following method for DNS config. touch /etc/resolv.conf vi /etc/resolv.conf nameserver 4.2.2.2 nameserver... (5 Replies)
Discussion started by: aemunathan
5 Replies

6. Programming

How to get free disk space size in C/C++ program( Solaris system)

How to get free disk space size in C/C++ program( Solaris system)? Is there any standard function or system function? Just like "df" or "getdfree" in Linux. (4 Replies)
Discussion started by: yidu
4 Replies

7. UNIX for Dummies Questions & Answers

Send Mail NOQUEUE low on space

Need help to resolve this message "NOQUEUE: low on space (have 18, SMTP-DAEMON needs 101 in /var/spool/mqueue)" Attached capture file from server HPUX 10.2 Ace root@PS01 : Aug 13 18:27:30 SANG last message repeated 7 times Aug 13 18:27:45 PS01 sendmail: NOQUEUE: low on space (have 18,... (2 Replies)
Discussion started by: real-chess
2 Replies

8. UNIX for Dummies Questions & Answers

Swap space is LOW

I checked the server and issued various command to investigated. but from teh output of swap -s and swap -l, i received the following swap -l swapfile dev swaplo blocks free /dev/vx/dsk/swapvol 197,7 16 4194800 4127696 /dev/vx/dsk/swap2 197,8 16 12582896... (3 Replies)
Discussion started by: TRUEST
3 Replies

9. UNIX for Dummies Questions & Answers

sendmail[5129]: NOQUEUE: low on space

sendmail: NOQUEUE: low on space (have 0, SMTP-DAEMON needs 101 in /var/spool/mqueue) We're getting this message on our Solaris (Apache/1.3.19) server. Can anyone give me an idea of what to look at? I'd really appreciate it! (2 Replies)
Discussion started by: sitemouse
2 Replies
Login or Register to Ask a Question