Disk Space Monitoring Script And Get Email Alert When CRITICAL

Ankam Ravi Kumar

Working as Linux / Storage Administrator L3. Interested in sharing the knowledge.

13 Responses

  1. Prashant says:

    Keep it up Ravi ………Thanks for sharing!!!!!!!!!!

  2. Ankam Ravi Kumar says:

    you can Add `hostname` in the mailer subject so that you can know from which host you received an alert.

  3. It would hv been better if along with hostname you could get the Filesystem name who’s usage is above your set threshold.

    • File System Usage is based on how much data is copied in partition. It may be used by multiple users in that way script output will be a cluttered.
      find / -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’ #Find the Large Size Files more than 100MB in size

  4. blank revanth gandhi says:

    Thankyou Sir 🙂

  5. blank Dharak Choksi says:

    I want to Setup MySQL Replication in Linux CentOS 7? How should i write Script for MySQL Replication Master – Salve in 2 Different Servers?

  6. blank Manoj says:

    DU=`/usr/bin/du -ks`
    ## Change ADMIN Mail address as per the requirement ##

    for path in $PATHS
    ## Validate the Percentage of Disk space ##
    DISK_AVAIL=`/bin/df -k / | grep -v Filesystem |awk ‘{print $5}’ |sed ‘s/%//g’`
    if [ $DISK_AVAIL -ge $THRESHOLD ]
    echo “Please clean up your stuff \n\n” > $MAILFILE
    $CAT $MAILFILE | $MAILER -s “Clean up stuff” $mailto

    but when i execute the script facing below error in CentOS 6.8 and it’s working on CentOS 7.2

    disk-monitor.sh: line 26: [: /: integer expression expected.

  7. blank Suraj says:

    ./diskspacemonitor.sh: line 28: /: is a directory
    why am getting error in the script
    i have copied as you mentioned

  8. blank Thanishkaa says:

    Hi Ravi
    If diskspace is > 80 % reached need to clear the logs automatically and place it in a path we create . Can you please help me how to write this script.

    Thanks & Regards
    Thanishkaa K

  9. blank raju says:

    how the mail will be sent ..? Do we need to install any tool for that. If yes, please help with the steps which tool and steps to install and configure for that.
    Thanks inadvance

  10. blank Raviteja says:

    Hi Ravi,
    I’m trying to monitoring the filesize using shell script.I’ve written the code but i’m facing some issue.


    value = 70
    df -H | grep -vE ‘^Filesystem|tmpfs|cdrom’ | awk ‘{ print $5 ” ” $1 }’ | while read output;
    echo $output
    usep=$(echo $output | awk ‘{ print $1}’ | cut -d’%’ -f1 )
    partition=$(echo $output | awk ‘{ print $2 }’ )
    if [[ “$usep” -ge “$value” ]]
    echo “The partition \”$partition\” on $(hostname) has used $usep% at $(date)” | mail -s “Disk space alert: $usep% used” xxxx@gmail.com
    echo “Disk Usage is normal”

    1.I’ve only 2 file systems(one is 88% & another one is 48%),If i execute my script i should get only one mail for the disk size of 88% (because it is more than 70 as per my code)but i’m getting for 48% also.Could you check & help me on this

Leave a Reply

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