I would say: don't use script for monitoring cpu. You may not get the correct cpu figures from inside the Linux and these cmds in scripts consumes huge cpu and I/O !!
I had a similiar code in bash script that took an hour to run. After converting it into a c-pgm it took seconds !! (This was not cpu monitoring, but other calculations) Do it in z/VM and a nice Rexx instead, much better ! ___________________________________________ Tore Agblad Volvo Information Technology Infrastructure Mainframe Design & Development, Linux servers Dept 4352 DA1S SE-405 08, Gothenburg Sweden Telephone: +46-31-3233569 E-mail: [email protected] http://www.volvo.com/volvoit/global/en-gb/ -----Original Message----- From: Linux on 390 Port [mailto:[email protected]] On Behalf Of Bauer, Bobby (NIH/CIT) [E] Sent: den 8 december 2010 20:41 To: [email protected] Subject: Need a little help with a Linux script I'm trying to write a little script and having trouble comparing integers and decimal numbers. The shell doesn't like it and I haven't been able to figure out how to get around it. Script is named zyx. 1 #!/bin/sh 2 ADMINA="[email protected]" 3 dt=`date '+%a %b %e %I:%M %p' ` 4 svr=`hostname` 5 ALERT=75 6 mpstat | grep -i all |awk '{print $4}'| 7 while read output; 8 do 9 cpuutil=`(echo $output | awk '{ print $1}' | cut -d'%' -f1 )` 10 set -x 11 if [ "$cpuutil" -ge $ALERT ]; then 12 echo "CPU utilization has risen beyond the alert threshold on $svr at $dt"| mail -vs "Alert:- CPU utilization is hi gh on $svr at $dt" $ADMINA 13 fi 14 done xyz + '[' 3.19 -ge 75 ']' /usr/sbin/xyz: line 11: [: 3.19: integer expression expected + read output mpstat is returns 3.19 and I'm trying, on line 11, to compare that to ALERT which is set to 75. I think I need to strip off the decimal part of 3.19 but haven't found any way to do it. Bobby Bauer Center for Information Technology National Institutes of Health Bethesda, MD 20892-5628 301-594-7474 ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 ---------------------------------------------------------------------- For more information on Linux on System z, visit http://wiki.linuxvm.org/ ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 ---------------------------------------------------------------------- For more information on Linux on System z, visit http://wiki.linuxvm.org/
