Counting Errors

Hi ,

I am trying to make a script which can count the errors in the log each time it scans. When ever it scans & counts the errors, it should do the comparison with the last count.

If the number is > than last time, you have errors.
If the number is < last time, ignore (new log file).
If the number is = last time, no change.

&

If errors <= 5 then WARN
If errors > 5 then ERROR

I have prepared the below given script ,,,but some how it is not working .
Kindly guide me , what is wrong with this script.

#!/bin/sh
tail -f sample_file.log > a.log
fCOUNT = grep ERROR a.log | wc -l
while (1)
do
iCOUNT= grep ERROR a.log | wc -l
COUNT=$(($fCOUNT -$iCOUNT))
if ($COUNT -eq 0) then
exit(1)
elif ($COUNT -le 5 ) then
echo "WARNING"
elif ($COUNT -gt 5) then
echo "ALERT"
fi
sleep 10
done

Regards

I'm using cat to read the errcnt file, you can use process substitution if you are using bash -

if [[ -w /path/to/errcnt ]] ; then
     cat /path/to/errcnt | read errcnt
else
     echo "0" > /path/to/errcnt
fi
grep -c 'ERROR' a.log | read newerrcnt dummy
if [[ $newerrcnt -gt $errcnt ]] ; then
       echo "New errors found"
        echo $newerrcnt" > /path/to/errcnt
else
       echo "okay no more errors found"
fi