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!

Unix script to check and alert file.

Status
Not open for further replies.

galger

MIS
Jan 16, 2002
79
US
It should every 5 minutes or so check the file for the most recent line or last line that starts out with the words "Full GC". It should take this line and evalutate the value/number that occurs after the "->" portion of the line up to the "K". If this number is >= 900000 then it should send out an alert.


[GC 974797K->947362K(1047424K), 0.1525772 secs]
[GC 977826K->950446K(1047424K), 0.1339467 secs]
[GC 980910K->955986K(1047424K), 0.1596349 secs]
[GC 986450K->960182K(1047424K), 0.1463073 secs]
[GC 990646K->964337K(1047424K), 0.1569067 secs]
[GC 994801K->970110K(1047424K), 0.1379262 secs]
[GC 1000574K->974444K(1047424K), 0.1388219 secs]
[GC 1004908K->978283K(1047424K), 0.1300475 secs]
[GC 1008747K->985118K(1047424K), 0.1550572 secs]
[GC 1015582K->991652K(1047424K), 0.1529226 secs]
[Full GC 1022116K->842734K(1047424K), 14.6826836 secs]
[GC 873198K->853428K(1047424K), 0.1773221 secs]
[GC 883892K->857167K(1047424K), 0.1137463 secs]
 
use the file as the first argument. try it
===============
#! /bin/ksh

while :
do
unset name
unset size

name=`tail -1 $1 | cut -c2-8`
echo $name
size=`tail -1 $1 | awk -F"->" '{ print $2 }' | awk -F"K" '{ print $1 }'`
echo $size
if [[ $name = "Full GC" && $size > 900000 ]]
then
echo alert | mail someone
fi
sleep 5 &
wait
done
 
oops, the minutes are incorrect. should be sleep 300.
 
a variation on the same theme.

#! /bin/ksh

typeset -i threshold=900000

while :
do

value=$(nawk -v value2compare="${threshold}" '
BEGIN {
FS="([(])|(->)"
}

/^\[Full GC / { value=$2;gsub("[^0-9]", "", value) }

END {
print (value == "") ? value2compare - 1 : value;
}

') $1

if [ "${value} -gt "${threshold}" ] ; then
echo alert | mail someone
fi
sleep 5 &
wait
done

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I need this script to keep reading a particular log ...???
Looking for the newest line with &quot;Full GC&quot; and if it goes over 900000K...

----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&quot;->&quot; '{ print $2 }' | awk -F&quot;K&quot; '{ 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
 
Thank you both for your help so far... thank you very much.!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top