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
"