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@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@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?
Mad Unix wrote: ...
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' |
Try changing "df -H" into "df -H -P"
Mogens
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@somewher.com mailto:me@somewher.com" # set alert level 90% is default ALERT=90
df -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@gmail.com wrote:
Hi ALL
#!/bin/sh # Shell script to monitor or watch the disk space
I use this one-liner:
df -P| awk '$5+0>90{print $0|"mutt -s df-k@`hostname` user@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)