Hi ALL #!/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 <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ---------------------------------------------------------------------- # Linux shell script to watch disk space (should work on other UNIX oses ) # SEE URL: http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html # set admin email so that you can get email ADMIN="me at 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 fi done Am trying to run the above script on my machine, it gave the following error [root at linux8 script]# ./disk_monitor.sh ./disk_monitor.sh: line 23: [: /dev/mapper/VolGroup00-LogVol00: integer expression expected ./disk_monitor.sh: line 23: [: /: integer expression expected Any help? -- Your search - madunix - did not match any documents. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20080728/a9ddfe6d/attachment-0001.html>
Mad Unix wrote: ...> df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' |Try changing "df -H" into "df -H -P" Mogens -- Mogens Kjaer, Carlsberg A/S, Computer Department Gamle Carlsberg Vej 10, DK-2500 Valby, Denmark Phone: +45 33 27 53 25, Fax: +45 33 27 47 08 Email: mk at crc.dk Homepage: http://www.crc.dk
Mad Unix wrote: I suggest make it a little bit lighter: inline corrections:> #!/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 <http://cyberciti.biz/fb/> > # This script is licensed under GNU GPL version 2.0 or above > # ------------------------------------------------------------------------- > # This script is part of nixCraft shell script collection (NSSC) > # Visit http://bash.cyberciti.biz/ for more information. > # ---------------------------------------------------------------------- > # Linux shell script to watch disk space (should work on other UNIX oses ) > # SEE URL: > http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html > # set admin email so that you can get email > ADMIN="me at somewher.com <mailto:me at somewher.com>" > # set alert level 90% is default > ALERT=90df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | while read partition size used free perc mnt ; do usep=$(echo $perc | tr -d '%' ) 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 fi done it works for me.
On Mon, Jul 28, 2008 at 3:33 AM, Mad Unix <madunix at gmail.com> wrote:> > > Hi ALL > > > #!/bin/sh > # Shell script to monitor or watch the disk spaceI use this one-liner: df -P| awk '$5+0>90{print $0|"mutt -s df-k@`hostname` user at domain.com"}' Probably, you should add -t ext3 to avoid reporting nfs or other special filesystems... -- Marcelo "?No ser? acaso que ?sta vida moderna est? teniendo m?s de moderna que de vida?" (Mafalda)