简单的iostat监视功能 ,第一个linux shell ,纪念一下
#!/bin/bash
SECS=3
INTERVAL=2
STATCOUNT=0
OS=$(uname)
case $OS in
Linux) SWITCH ='-c'
F1=1
F2=2
F3=3
F4=4
;;
esac
echo "\n the operating systerm is $OS\n"
echo "Gathering CPU Statistics using iostat...\n"
echo "There are $INTERVAL sampling periods with"
echo "each interval lasting $SECS seconds"
echo "\n...please wait while gathering statics....\n"
iostat $SWITCH $SECS $INTERVAL |egrep -v '[a-zA-Z]|^$'\
|awk '{print $'$F1',$'$F2',$'$F3',$'$F3',$'$F4'}'\
|while read FIRST SECOND THIRD FOURTH
do
if((STATCOUNT==1))
then
echo "\n user part is ${FIRST}%"
echo "nice part is ${SECOND}%"
echo "systerm part is ${THIRD}%"
echo "I/O wait stat is ${FOURTH}%\n"
fi
((STATCOUNT=STATCOUNT+1))
done