Operating System - HP-UX
1847565 Members
3463 Online
110265 Solutions
New Discussion

compare script question ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

compare script question ..

Hello everyone .. I have this out put from online.log:

04:49:08 Checkpoint Completed: duration was 1 seconds.
04:49:12 Checkpoint Completed: duration was 0 seconds.
04:56:13 Checkpoint Completed: duration was 0 seconds.
08:20:57 Checkpoint Completed: duration was 17 seconds.
08:21:30 Checkpoint Completed: duration was 0 seconds.
14:51:00 Checkpoint Completed: duration was 4 seconds.
14:51:25 Checkpoint Completed: duration was 0 seconds.

The objective is to get the number of seconds and warn me if at any time they are greater then 15. Here is what I got so far ..

grep duration /usr/informix/online.log | grep -v Fuzzy | awk '{print $6}'

gives me

1
0
0
17
0
4
0

That gives me just the lines above and then only gives me the seconds ..

So then I tried

grep duration /usr/informix/online.log | grep -v Fuzzy | awk '{print $6}'| read numb

if [ $numb -gt 15 ]
then
echo "You have long checkpoints"
else
echo " Everything is fine"
fi


But that does not work for me. For somereason I cant feed the line of numbers to my test if statement. What Am I missing? I know its simple ..

Thanks

Richard
14 REPLIES 14
harry d brown jr
Honored Contributor
Solution

Re: compare script question ..

#!/usr/bin/ksh
grep duration /tmp/online.log | grep -v Fuzzy | awk '{print $6}'| sort -rn| whil
e read numb
do
echo $numb
if [ $numb -gt 15 ]
then
echo "You have long checkpoints"
else
echo " Everything is fine"
fi
done

note I sorted the list in reverse numerical order.

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: compare script question ..

of course grep can nail them also:

grep duration /tmp/online.log | grep -v Fuzzy | awk '{print $6}'| grep "[0-9][0-9]"

live free or die
harry
Live Free or Die
SHABU KHAN
Trusted Contributor

Re: compare script question ..

Hi,

Your script is not working because you missed "while" before the read

#!/bin/ksh

awk '/duration/{print $6}' test | while read NUM; do
if [[ ${NUM} -gt "15" ]]; then
echo "you have long checkpoints"
else
echo "okay"
fi
done

-Shabu
H.Merijn Brand (procura
Honored Contributor

Re: compare script question ..

# perl -ne '/Fuzzy/ or /duration.*?(\d+)/ && $1 > 15 && print' online.log
Enjoy, Have FUN! H.Merijn
Krishna Prasad
Trusted Contributor

Re: compare script question ..

grep duration /usr/informix/online.log | grep -v Fuzzy | awk ' $6 > 15 {printf "There is a long checkpoint of %s\n",$6}'

Positive Results requires Positive Thinking
harry d brown jr
Honored Contributor

Re: compare script question ..

I like procura's, but I'd modify RON's and display the entire line so you know when it happened!

live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: compare script question ..

Hey everyone thanks for your help .. Here is what I decided to go with ..

grep duration /usr/informix/online.log | grep -v Fuzzy | awk ' $6 > 15 {printf "
There is a long checkpoint of %s\n",$6}'
grep duration /usr/informix/online.log | grep -v Fuzzy | awk ' $6 > 15 ' | read
numb
grep "$numb" /usr/informix/online.log


Gives me

There is a long checkpoint of 17
08:20:57 Checkpoint Completed: duration was 17 seconds.

Thanks

Richard
someone_4
Honored Contributor

Re: compare script question ..

procura your solution if very nice .. I like it. My friend who loves perl will enjoy that.


Richard
harry d brown jr
Honored Contributor

Re: compare script question ..

Richard,

#!/usr/bin/ksh
grep duration /tmp/online.log | grep -v Fuzzy | awk '$6 > 15 {printf "There is a
long checkpoint of %s\n",$6;printf "%s\n",$0;}'


will find all the lines and print their corresponding line. The solution you gave will report the same FULL-LINE if TWO or MORE TIMES are > 15 and equal

line these two lines:
04:49:08 Checkpoint Completed: duration was 1 seconds.
04:49:12 Checkpoint Completed: duration was 0 seconds.
04:56:13 Checkpoint Completed: duration was 0 seconds.
08:20:57 Checkpoint Completed: duration was 17 seconds.
08:21:30 Checkpoint Completed: duration was 0 seconds.
14:51:00 Checkpoint Completed: duration was 4 seconds.
14:51:25 Checkpoint Completed: duration was 17 seconds.

yours will display :

08:20:57 Checkpoint Completed: duration was 17 seconds.

TWICE, when it should display:

08:20:57 Checkpoint Completed: duration was 17 seconds.
14:51:25 Checkpoint Completed: duration was 17 seconds.

give my modifications to your solution a zip

live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: compare script question ..

wow .. that was good ..
Would you mind breaking it down for me? I understand everything up to the printf ..

of %s\n",$6;printf "%s\n",$0;}'

is the part I dont understand. What I do somewhat understand is that you are printing the output There is a long checkpoint with the $6 (6th row) which is what gives us :

There is a long checkpoint of 17


#!/usr/bin/ksh
grep duration /usr/informix/online.log | grep -v Fuzzy | awk '$6 > 15 {printf "T
here is a long checkpoint of %s\n",$6;printf "%s\n",$0;}'

And just wondering how long have you been writting scripts? It seems that it is 2nd nature to you. Did you read books or just learned as you did.

Thanks,
Richard
harry d brown jr
Honored Contributor

Re: compare script question ..

Richard,

Both, but first by fire. 12years ago I ported banking software from a Honeywell to an AIX box and I had to learn unix and learn it quick. I've been a developer for EON'S (24 years now).

Here:

grep duration /tmp/online.log | grep -v Fuzzy |
awk '$6 > 15 {printf "There is a
long checkpoint of %s\n",$6;
printf "%s\n",$0;}'

The line:
awk '$6 > 15 {printf "There is a long checkpoint of %s\n",$6;

like Ron suggested matches when the 6th value on the line is greater than 15, then the BODY of the AWK script kicks in:

{printf "There is a long checkpoint of %s\n",$6;
printf "%s\n",$0;}'

The lines in AWK are seperated by ";'s" and $0 is the whole line. Printf's are about the same in perl, C, and Awk.

And will you please learn perl? hehehe

Live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: compare script question ..

lol
thanks harry .. And I am working on learning perl seems to be a pretty cool code. I have SAMS Teach yourself perl in 24 hours. To me it was full of fluff. I am thinking thats why I got burnt out on Perl. But I am willing to try again. Any better books out there?

Richard
harry d brown jr
Honored Contributor

Re: compare script question ..

Richard,

being a techno-geek I like the O'reilly books as reference manuals. There are a lot good web sites with good crap, hell, I' a cut and paster!!

http://www.perlmonks.org/

http://www.planet-source-code.com/vb/default.asp?lngWId=6#categories

http://www.perlnow.com/

http://www.perl.com/CPAN-local/scripts/

http://use.perl.org/

http://www.sysadminmag.com/tpj/

http://www.perl.org/

http://www-genome.wi.mit.edu/WWW/examples/Ch9/


and at least a few thousand more!

live free or die
harry

Live Free or Die
H.Merijn Brand (procura
Honored Contributor

Re: compare script question ..

And be sure to install at least perl-5.6.1 (some people on this forum still use 4.036 :)

That way I'll be sure my answers will work as expected.
Enjoy, Have FUN! H.Merijn