Shell programming disk monitoring (evaluation of available space depletion time, mail Notification to the Administrator) sets the monitoring disk to/dev/md0; if the file system usage is greater than 90%, the three functions are called in sequence to estimate the time used up by the file system, and the results are sent to the Administrator. #! /Bin/bash # This script is used to monitor disk. #6/20/11 # define the write speed of the function compute file system function disk_speed () {A = 'df-k | grep "$1" | awk '{print $3} ''sleep 30 B = 'df-k | grep" $1 "| awk' {print $3} 'd = 'expr $ B-$ a' SPEED = 'expr $ D/30' echo $ SPEED unset a B D SPEED} # define estimated disk space depletion time function avai_time () {FREE = 'df-k | grep "$1" | awk '{print $4} ''if TIME = 'expr $ FREE/$ 2' then if [$ TIME- ge 60] then A = 'expr $ TI ME/60' echo $ A "minutes" unset free time return 0 else echo "Unknow" unset free time return 0 fi else echo "Unknow" unset free time return 1 fi} # Definition function content () {TEMP_FILE =/root/disk_monitor.tmp echo "Warning disk:" $1> $ TEMP_FILE echo "Used space:" $2 >>$ TEMP_FILE echo "Available space: "$3 >>$ TEMP_FILE echo" Use %: "$4" % ">>$ TEMP_FILE echo" Write speed: "$5 >>$ TEMP_FILE echo" Estimated Time remaining: "$6 >>$ TEMP_FILE echo" Now time: "'date +" % Y-% m-% d % H: % M "'> $ TEMP_FILE unset TEMP_FILE return 0} # define the file system to be monitored MON_DISK =/dev/md0USED = 'df-h | grep" $ MON_DISK "| awk' {print $5} '| sed's/% // ''# determines whether the usage rate is greater than 90%, if yes, run the statement after then if [$ USED-ge 90] then USED_SPACE = 'df-h | grep "$ MON_DISK" | awk '{print $4} ''avai_space =' df-h | grep "$ MON_DISK" | awk '{print $3} ''W_SPEED = 'disk _ speed $ MON_DIS K'if [$ W_SPEED! = 0] then S_TIME = 'avai _ time $ MON_DISK $ w_speed' else S_TIME = "Unknow" fi content $ MON_DISK $ USED_SPACE $ AVAI_SPACE $ USED $ W_SPEED $ S_TIME mail-s "Disk "warning "root </root/disk_monitor.tmp rm-rf/root/disk_monitor.tmp unset MON_DISK USED USED_SPACE AVAI_SPACE W_SPEED S_TIMEfi