0

My script is:

abc=$(df -h | sed s/%//g | awk '{ if($5 > 80) print "Alert "$0;}' | awk '{print $2,$6}') \
    && echo -e "Dear All, \n\n$abc\n\nABC" \
     | mailx -s "Disk partition" support@something.com

Here when condition is not true, I get the following output in my email:

Filesystem Use

However I want mail only when disk usage exceeds 80%.

1
  • Did you consider enabling disk quotas? BTW, did you read documentation of GNU awk? You probably should use it once (no need for your pipeline) and invoke mailx inside your awk script – Basile Starynkevitch Feb 8 '16 at 7:43
1

Recommend using a) mulitliners for such things, b) to check 'nagios' and co. For the first try, check out this script:

#!/bin/bash
function chk () {
        # declare as integer to  be used in arithmetic expressions
        declare -i usage
        echo "checking mount $1. has $2 percent"
        usage=$2

        if [[ ${usage} -gt 80 ]] ; then 
                echo "alert for partition $1"
                #echo -e "Dear ..." | mailx -s "Disk partition ..." 
        fi
}
df -h | grep -v "none" | tail -n +2 | sed s/%//g | while read a b c d e f; 
        do chk $a $e; 

done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.