Yesterday I wrote a post when I found a script to monitor disk space in a server and getting alert on thresh hold level. However that script just send a notification when disk space is on thresh hold, but I wanted to get disk usage on daily basis therefore I made some modifications in script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#!/bin/sh # Shell script to monitor or watch the disk space # It will send an email to $ADMIN, if the (free avilable) percentage # of space is >= 90% # ------------------------------------------------------------------------- # Copyright (c) 2005 nixCraft project #-------------------------------------------------------------------------- # Modified by http://WWW.MyliteratureTechLife.com # Added code to send an email with current usage # ---------------------------------------------------------------------- # Linux shell script to watch disk space (should work on other UNIX oses ) # SEE URL: http://www.techat.net/shell-script-to-monitor-current-disk-space-and-getting-alert-on-thresh-hold-level/ # set admin email so that you can get email ADMIN="[email protected]" # set alert level 90% is default ALERT=90 df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) partition=$(echo $output | awk '{ print $2 }' ) if [ $usep -ge $ALERT ]; then echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | mail -s "Alert: Almost out of disk space $usep%" $ADMIN else echo "Still enough space \"$partition ($usep%)\" on $(hostname) as on $(date)" | mail -s "Alert: Still enough disk space $usep%" $ADMIN fi done |
Comment Policy:
Your words are your own, so be nice and helpful if you can. Please, only use your real name, not your business name or keywords. Using business name or keywords instead of your real name will lead to the comment being deleted. Anonymous commenting is not allowed either. Limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please.