Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep reading a particular log ...???

Status
Not open for further replies.

galger

MIS
Jan 16, 2002
79
US
I need this script to keep reading a particular log ...???
Looking for the newest line with "Full GC" and if it goes over 900000 between "->" and "K"
Close? (script below)

----Log file----
[Full GC 1022116K->910000K(1047424K), 14.6826836 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 977826K->950446K(1047424K), 0.1339467 secs]
---Logfile--


Here is what I have so far:

#! /bin/ksh
while :
do
unset name
unset size

name=`tail -100 datafil.dat | cut -c2-8`
echo $name
size=`tail -100 datafil.dat | awk -F"->" '{ print $2 }' | awk -F"K" '{ print $1 }'`
echo $size
if [[ $name = &quot;Full GC&quot; && $size < 900000 ]]
then
echo &quot;alert by mail&quot;
exit 1
fi
sleep 5 &
wait
done
 
Like so (this is an AWK program)
Code:
#!/bin/awk -f
/Full GC/ && match($0,&quot;-\>[0-9]+K\(&quot;) {
    size = substr($0,RSTART+2,RLENGTH-4)
    if ( size >= 900000 ) {
        print &quot;send mail&quot;
    }
}

Save it in a file (say prog.awk), then run as
Code:
    awk -f prog.awk datafil.dat
 
Changed it a little.

#!/bin/awk -f

/Full GC/ && match($0,/-\>[0-9]+K\(/)
{
size = substr($0,RSTART+2,RLENGTH-4)
if ( size >= 900000 ) {
print &quot;send mail&quot;
exit 0
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top