Sponsored Content
Top Forums Shell Programming and Scripting Sending an email if system disk space is low Post 302900654 by taf130 on Thursday 8th of May 2014 03:49:44 AM
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();
}

 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
SCRIPT-EMAIL(8) 					  System Administration Commands					   SCRIPT-EMAIL(8)

NAME
script-email - Amanda script to send email notifications DESCRIPTION
script-email is an Amanda script implementing the Script API. It should not be run by users directly. It sends a notification email to the addresses specified in the MAILTO property. PROPERTIES
This section lists the properties that control script-email's functionality. See amanda-scripts(7) for information on the Script API, script configuration. MAILTO List of email addresses that will receive an email on command execution. It is a multi-valued property: property "MAILTO" "amanda@domain.com" "sysadmin@domain.com" "amandauser@domain.com" EXAMPLE
In this example, script-email is scheduled to be run before the DLE, on the server. The unqualified email address amanda will be passed to the email system unchanged. The script is then attached to a dumptype, which can then be specified for any DLEs which require notification. define script-tool pre-email { comment "email me before this DLE is backed up" plugin "script-email" execute-on pre-dle-backup execute-where server property "mailto" "amanda" } define dumptype user-tar-email { user-tar script "pre-email" } SEE ALSO
amanda(8), amanda.conf(5), amanda-client.conf(5), amanda-scripts(7) The Amanda Wiki: : http://wiki.zmanda.com/ AUTHORS
Jean-Louis Martineau <martineau@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Dustin J. Mitchell <dustin@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Amanda 3.3.3 01/10/2013 SCRIPT-EMAIL(8)
All times are GMT -4. The time now is 05:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy