按小时统计unix机器内存和cpu使用率
给脚本赋权限
chmod 755 *.sh
后台执行该脚本
nohup sum_capa.sh &
x=0totMem=`vmstat | grep 'mem=' | awk -F\= '{ print $3 }' | awk -F\M '{print $1 }'`totMem1=` echo "$totMem * 200 " | bc `while truedo strDate=`date +"%Y%m%d"` strTime=`date +"%Y%m%d%H"` strRun=`vmstat 1 4 | tail -1 | awk '{ print " "$3" "$14" "$15 }' ` echo $strTime" "$totMem1$strRun >> capa_$strDate.txt sleep 56 x=`expr $x + 1` if [ $x -gt 3000 ] then break fidone
if [ "$#" -ne 1 ]then echo "Usage:get_capa.sh yyyymmdd" exit 1fiecho "Hour Mem(%) Cpu(%) " > capa_hour_$1.txthh="00"x=0while truedo if [ x -lt 10 ] then hh="0"$x else hh=$x fi strTmp=`grep $1$hh capa_$1.txt | awk 'BEGIN{allMem=0;useMem=0;memRate=0;cpuRate=0;num=0;allCpu=0;} { allMem=allMem+$2;useMem=useMem+$3;num=num+1;allCpu=allCpu+$4+$5;} END{ if (allMem>0) { memRate=useMem*100/allMem;cpuRate=allCpu/num;} print memRate" "cpuRate}'` echo $hh" "$strTmp >> capa_hour_$1.txt x=`expr $x + 1` if [ $x -gt 23 ] then break fidonecat capa_hour_$1.txt
if [ "$#" -ne 3 ]then echo "Usage:sum_tran.sh yyyy mm dd" exit 1fiecho "Hour Trans" > tran_hour_$1$2$3.txthh="00"x=0while truedo if [ x -lt 10 ] then hh="0"$x else hh=$x fi num=`grep TxRunAction /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|grep $1":"$hh |wc -l` echo $hh" "$num >> tran_hour_$1$2$3.txt x=`expr $x + 1` if [ $x -gt 23 ] then break fidonecat tran_hour_$1$2$3.txtnum=`cat /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log | wc -l`echo "TotTrans="$numnum=`grep TxRunAction /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|wc -l`echo "TxRunTrans="$numnum=`grep LinkageTX /usr/IBM/HTTPServer/logs/access.$1.$2.$3.log|wc -l`echo "LinkTrans="$num
if [ "$#" -ne 1 ]then echo "Usage:db_20w.sh ddmmyyyy" exit 1fidb2 "connect to ecap "db2 "select count(*) from ecapdb.t_tran_log where HEAD_DATE='"$1"' "