Email alert on disk space outage in linux

For Send mail Tutorial Click Here

Need to be installed sendmail ( yum install sendmail) and mailx (yum install mailx)

Create a shell script in linux.

vi diskalert.sh

#!/bin/sh
support=”itsupport@xyz.com”
# set alert level 90% is default
ALERT=90
df -HP | grep -vE ‘^Filesystem|tmpfs|cdrom’ |
  while read partition size used free perc mnt ;
  do
    usep=$(echo $perc | tr -d ‘%’ )
    if [ $usep -ge $ALERT ]; then
      echo “Running out of space “$partition ($usep%)” on $(hostname) as
  on $(date)” |
       mail -s “Alert: Almost out of disk space – $usep%” $support
    fi
  done
Now make this script executable as below.
chmod 777 diskalert.sh
and now set the cron job as follows.
0 09 * * * /diskalert.sh

 

Related Posts

  • 33
    You can use gmail or any other SMTP server as a smart host to send all messages from your Linux / UNIX desktop systems. You need to use a simple program called ssmtp. It accepts a mail stream on standard input with recipients specified on the command line and synchronously…
    Tags: mail, send, sendmail, email, shell, install, script

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: