I am trying to get the details of iowait for last hour using sar. When I give date as argument it works.
# sar -u -s 22:24:00 -e 23:24:00
Linux 2.6.35.13-26 (XX.server.com) 04/11/2012
10:30:03 PM CPU %user %nice %system %iowait %idle
10:40:04 PM all 5.03 0.01 3.20 48.95 42.81
10:50:04 PM all 3.58 0.02 3.88 56.53 36.00
Average: all 4.30 0.02 3.53 52.74 39.41
10:58:34 PM LINUX RESTART
11:10:01 PM CPU %user %nice %system %iowait %idle
11:20:01 PM all 4.72 4.17 2.02 39.23 49.86
Average: all 4.72 4.17 2.02 39.23 49.86
But when I pass hour and minute as variable it does not work. Variable contain the correct value.
# currhour=`date | awk {'print $4'} | cut -d: -f 1` ; currmin=`date | awk {'print $4'} | cut -d: -f 2`; lasthour=`expr $currhour - 01` ; lasthour=`printf %02d $lasthour` ; sar -u -s $currhour:$currmin:00 -e $lasthour:$currmin:00
Linux 2.6.35.13-26 (XX.server.com) 04/11/2012
Variable outout
# currhour=`date | awk {'print $4'} | cut -d: -f 1` ; currmin=`date | awk {'print $4'} | cut -d: -f 2`; lasthour=`expr $currhour - 01` ; lasthour=`printf %02d $lasthour` ; echo -e "currhour $currhour \n" ; echo -e "currmin $currmin \n" ; echo -e "lasthour $lasthour \n"
currhour 23
currmin 57
lasthour 22