按小时统计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"' "1 楼 codingstandards 2011-10-15 楼主,整理一下格式啊