Compare output from awk to a value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare output from awk to a value
# 1  
Old 03-06-2006
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
# 2  
Old 03-06-2006
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.
# 3  
Old 03-06-2006
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

# 4  
Old 03-06-2006
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?
# 5  
Old 03-06-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Parse output and then compare column wise with awk

Hello, I am trying to write a script to parse the output of data and then alert based on certain conditions This is the output of my script (STRING) Name = Joe (FLOAT64) BMI = 34 (FLOAT64) Weight = 156 (STRING) Name = Sam (FLOAT64) BMI = 32 (FLOAT64) Weight = 180 and so on it repeats... (4 Replies)
Discussion started by: sidnow
4 Replies

2. Shell Programming and Scripting

How to compare below output?

I'm very new to shell scripting, below is my output in status.txt CM TARGET ACTUAL ---------------------------------- ---------- ---------- Conflict Resolution Manager 1 1 Internal Manager 1 ... (6 Replies)
Discussion started by: dhaawale
6 Replies

3. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

4. Shell Programming and Scripting

Compare two files and output difference, by first field using awk.

It seems like a common task, but I haven't been able to find the solution. vitallog.txt 1310,John,Hancock 13211,Steven,Mills 122,Jane,Doe 138,Thoms,Doe 1500,Micheal,May vitalinfo.txt 12122,Jane,Thomas 122,Janes,Does 123,Paul,Kite **OUTPUT** vitalfiltered.txt 12122,Jane,Thomas... (2 Replies)
Discussion started by: charles33
2 Replies

5. Shell Programming and Scripting

awk compare 2 columns, 2 files, output whole line

Hello, I have not been able to find what I'm looking for via searching the forum. I could use some help with an awk script or one-liner to solve this simple problem. I have two files. If $1 and $2 from file1 match $1 and $2 from file2, print the whole line from file2. Example file1 ... (2 Replies)
Discussion started by: jm4smtddd
2 Replies

6. Shell Programming and Scripting

awk to compare diff output by fields

Diff output as follows: < AAA BBB CCC DDD EEE 123 > PPP QQQ RRR SSS TTT 111 > VVV WWW XXX YYY ZZZ 333 > AAA BBB CCC DDD EEE 124 How can i use awk to compare the last field to determine if the counter has increased, and need to ensure that the first 4 fields must have the same... (15 Replies)
Discussion started by: ux4me
15 Replies

7. Shell Programming and Scripting

AWK Compare files, different fields, output

Hi All, Looking for a quick AWK script to output some differences between two files. FILE1 device1 1.1.1.1 PINGS device1 2.2.2.2 PINGS FILE2 2862 SITE1 device1-prod 1.1.1.1 icmp - 0 ... (4 Replies)
Discussion started by: stacky69
4 Replies

8. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

9. Shell Programming and Scripting

compare 2 files > output new to third

Hi, I have a question of comparing to files and output the result third file where file1 is the mainfile containing processed dir data and 2nd file grepīs dirīs data again (could be newer dirs comparing file1<file2) now i wanna make shure that output in file3 only contains newer dirs hx... (1 Reply)
Discussion started by: needle
1 Replies

10. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies
Login or Register to Ask a Question