Shell script to monitor current disk space and getting alert on thresh hold level
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.
#!/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.myliteraturetechlife.com/shell-script-to-monitor-current-disk-space-and-getting-alert-on-thresh-hold-level/ # set admin email so that you can get email ADMIN="me@somewher.com" # 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 |
Tags: disk space, How to, monitor
0 Responses


