INSTALLATION DOCUMENTS BY RAVI

Sunday, June 11, 2017

Shell script for getting an Alert Mail if the Disk Usage reaches 90% of space Linux

Prerequisites:
Any one of the below mail utility must be present on the linux server
1. sendmail
2. mail
3. mutt
4. ssmtp
5. telnet

1. Below script will send an alert mail if the disk usage space of a directory in linux server reaches 90%
In this script I used "mail" utility for sending alert mails

ADMIN="lravikumarvsp@gmail.com"
ALERT=90
message=$(df -h | awk -v ALERT="$ALERT" '
    NR == 1 {next}
    $1 == "abc:/xyz/pqr" {next}
    $1 == "tmpfs" {next}
    $1 == "/dev/cdrom" {next}
    1 {sub(/%/,"",$5)}
    $5 >= ALERT {printf "%s is almost full: %d%%\n", $1, $5}
')
if [ -n "$message" ]; then
  echo "$message" | mail -s "Alert: Almost out of disk space" "$ADMIN"
fi

2. Below script will send an alert mail if the disk usage space of the root partition in linux server exceeds 90%

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $4}' | sed 's/%//g')
THRESHOLD=90
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
    mail -s 'Disk Space Alert' lravikumarvsp@gmail.com << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi


No comments:

Post a Comment

Loading xml file data to oracle table using python

Sample xml file (test.xml): <?xml version="1.0"?> <data>     <customer name="Ravi" >     ...