分类:
2007-09-30 10:12:00
#!/sbin/sh #define logfile&hostlists hostlists="/etc/chk/hosts.sar-u.lst" if [ ! -d /etc/chk/log/`date +%Y%m%d` ];then mkdir -p /etc/chk/log/`date +%Y%m%d` fi logfile=/etc/chk/log/`date +%Y%m%d`/sar-u.log cat /dev/null >$logfile #monitor the check-logfile in-real-time #tail -f $logfile & #define shell-script's option if [ "$1" = "" ] then intv=60 else intv=$1 fi if [ "$2" = "" ] then counts=180 else counts=$2 fi if [ "$3" = "" ] then sleeptimes=60 else sleeptimes=$3 fi #main shell-script begin for i in `cat $hostlists | grep -v \#` do #clear old-checking-log of today if [ -f $logfile.$i ] then cat /dev/null >$logfile.$i else touch $logfile.$i fi #begin to check item echo "check $i" (sleep 10;echo "sar -u $intv $counts &";sleep $(((intv+intv/10+1)*(counts+10)));) | rlogin $i | egrep "^$i|Average|:|idle" >>$logfile.$i & done #monitor if check-log-file has been finished while :;do working="done" for i in `cat $hostlists | grep -v \#` do if [ ! -f $logfile.$i ];then working="nofile" elif [ `ls -l $logfile.$i | awk '{print $5}'` -eq 0 ];then working="zero" fi done if [ "$working" = "done" ];then break fi sleep $sleeptimes done #get brief-result from detail check-log-file for per-host sleep 5 for i in `cat $hostlists | grep -v \#` do cat $logfile.$i | egrep "sar|Average|idle" >>$logfile echo >>$logfile done #exit and kill the tail-f process echo "" echo "the host in $hostlists has not been checked:" echo `cat $hostlists | grep \#` echo "all the sar-d brief-result has been saved to $logfile." echo "for detail result,please watch $logfile.hostname file." #kill `ps -f -u root | grep "tail -f $logfile" | awk '{print $2}'` >/dev/null exit 0 |