Monitoring script for a log file

Hi,

I need to get a script working to monitor a log file and throw an alert via mailx as soon as a particular error is encountered.
I do not want repeatative email notifications of same error so simply cat logfile and grepping the error would not work.

Here is what i planned but it seems read line dosent work with tail -f.

"

#!/bin/bash
logLocation="/logs/user.log"
Email_Dest="dummy@email.com"
tail -f $logLocation|while read LINE;do
echo $line
if [ `echo $line|grep socket|wc -l` -ne 0 ]; then
        echo "test successful!";
        mailx -r Admin -s "Socket error reported in log." $Email_Dest < echo $line;
else if [ `echo $line|grep timeout|wc -l` -ne 0 ]; then
        mailx -r Admin -s "Timeout error reported in log." $Email_Dest < echo $line;
fi
fi
done

"

Linux is case sensitive.
So read LINE and echo $line do not refer to the same variable, therefor $line is empty.

I suggest make the read LINE to small caps, as the rest of the code is using $line .

hth

1 Like

I am an IDIOT! Thank you very much!!!