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

SQL query to find whether OdiSendMail is configured or not ODI 12c

In the SQL developer connect to the ODI work repository user (Ex: DEV_ODI_REPO) and run the below query. select SCEN_NAME,TASK_NAME3,DE...