#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
用法: saru.sh [intervals] [counts] [sleeptimes] note: default value: interval=30,counts=60,sleeptimes=60 sleeptimes:the interval-times, to check if detail-check-logfile has been finished. you must be sure that the machine in the hostlist-file can be logined by use "rlogin" command. example: ./saru.sh 30 60 & ./saru.sh 5 10 10 & nohup ./saru.sh &