The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare columns from seven files and print the output smriti_shridhar Shell Programming and Scripting 7 06-10-2008 09:22 PM
Compare 2 files and give uniq output rauphelhunter Shell Programming and Scripting 1 05-12-2008 01:47 PM
compare two col from 2 files, and output uniq from file 1 pp56825 Shell Programming and Scripting 2 01-10-2008 07:10 AM
Aggregate values in a file & compare with sql output shiroh_1982 UNIX for Dummies Questions & Answers 1 09-02-2007 04:40 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-05-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
Compare output from awk to a value

I need to write a shell script which checks the CPU utilization is above 90% for a particular process.

So far I have done this

prstat 0 1 | grep weblogic | awk '{print $9}'

This give an output like this

0.1%
0.0%
0.0%
0.0%
0.0%


Now I need to assign this to an array and check if the value exceeds 90%.
If so then I should print an alert message in the script.

Please help me to do the same.

Thanks
Joe
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-06-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,317
Try running this:
Code:
prstat 0 1 | grep weblogic | awk '{print $9}' | while read line;
do
if [ ${line%%\%} -gt 90 ]; then
        # send alert here!
fi
done
Note, this will not work if the % value is something like 90.7%. It has to be 91 or more.
Reply With Quote
  #3 (permalink)  
Old 03-06-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
Quote:
Note, this will not work if the % value is something like 90.7%. It has to be 91 or more.
this one would do,

assuming single precision,

Code:
prstat 0 1 | grep weblogic | awk '{print $9}' | sed 's/%//' | while line do
 if [ `echo $line \* 10 | bc` -gt 900 ]
 then
 echo "$line greater than 90"
 else
 echo "$line not greater than 90"
 fi
 done
Reply With Quote
  #4 (permalink)  
Old 03-06-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,317
Quote:
Originally Posted by matrixmadhan
this one would do,

assuming single precision,

Code:
prstat 0 1 | grep weblogic | awk '{print $9}' | sed 's/%//' | while line do
 if [ `echo $line \* 10 | bc` -gt 900 ]
 then
 echo "$line greater than 90"
 else
 echo "$line not greater than 90"
 fi
 done
Nice one. Instead of assuming single precision, why not use 100 as the multiplier and check against 9000?
Reply With Quote
  #5 (permalink)  
Old 03-06-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
Quote:
Nice one. Instead of assuming single precision, why not use 100 as the multiplier and check against 9000?
ya, ...

i just made a quick glance at the output of the command and
hence restricted it to single precision
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0