Disk Space Monitoring Script And Get Email Alert When CRITICAL

Ankam Ravi Kumar

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

10 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. Rohit Rajput says:

    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. revanth gandhi says:

    Thankyou Sir 🙂

  5. 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. 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. Suraj says:

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

  8. 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

Leave a Reply