LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-24-2014, 05:53 AM   #1
yogesh_attarde
Member
 
Registered: Jan 2010
Posts: 82

Rep: Reputation: 1
Disk usage warning and critical mail


Hi All,

I have written a bash shell script to check disk usage and will send mail if it is above 90%. This script will run everyday. My script is as below:

Code:
#!/bin/sh
alert=90
rm -rf /tmp/disk_alert.txt
touch /tmp/disk_alert.txt

df -HP | grep -vE '^Filesystem|tmpfs|cdrom|h|mnt|apps|mirror' | awk '{ print $5 " " $6 " " $1 }' | while read output;
do
#  echo $output
        usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
        partition=$(echo $output | awk '{ print $2 }' )
        if [ "$usep" -gt "$alert" ]
        then
                echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" >> /tmp/disk_alert.txt
        fi
done
if [ -s /tmp/disk_alert.txt ]
        then
                cat /tmp/disk_alert.txt | mail -s "Alert: Almost out of disk space" yogesh@gmail.com
        fi
Now I want it to run everyday morning at 11.00 AM (For this I will setup crontab) and I want to modify it in such a way if disk usage is 80% it should send warning mail only once and if it is 90% it should send alert mail everyday.

Last edited by yogesh_attarde; 09-24-2014 at 07:06 AM.
 
Old 09-24-2014, 09:23 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,666

Rep: Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147Reputation: 8147
Quote:
Originally Posted by yogesh_attarde View Post
Hi All,
I have written a bash shell script to check disk usage and will send mail if it is above 90%. This script will run everyday. My script is as below:

Now I want it to run everyday morning at 11.00 AM (For this I will setup crontab) and I want to modify it in such a way if disk usage is 80% it should send warning mail only once and if it is 90% it should send alert mail everyday.
Ok, so make whatever modifications you'd like...let us know if you're having an actual problem doing it, and we can try to help.

If you're looking for suggestions, you could always always output the disk-usage number into a file and read it, along with the date/time stamp. If the disk usage is between 80 and 89, and the date was yesterday, that means the mail went OUT yesterday, and there's no need to send it again. If it's 90 or more, send an email regardless.

If you're looking for us to make these changes FOR YOU, then post this in the LQ Job Marketplace, along with how much you'd like to pay.
 
Old 09-25-2014, 04:57 AM   #3
yogesh_attarde
Member
 
Registered: Jan 2010
Posts: 82

Original Poster
Rep: Reputation: 1
Thanks TBOne for the reply, I used the other logic and updated the script according to my need.
 
  


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
nagios notification different interval for warning and critical slowerogue Linux - Newbie 4 04-01-2014 12:39 AM
gnome-session WARNING/CRITICAL ThePowerTool Linux - Server 1 04-28-2013 06:34 AM
Swap memory treshold - warning - critical kopper27 Linux - Newbie 4 03-20-2012 06:28 PM
FC8 on laptop: no warning for critical battery? xpucto Fedora 2 11-29-2007 08:02 AM
Yamipod. Gtk-CRITICAL, Gdk-WARNING. How to resolve? lebabyg Linux - Software 2 04-01-2006 06:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:11 PM.

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
Open Source Consulting | Domain Registration