Quote:
Originally Posted by Vignesh Radhakrishnan
Hi All,
I want to monitor the logs continuously and sends a error if keyword/pattern matches and continues the monitoringI tried below script
Code:
tail -F /data/log/test.log |
egrep -io 'got signal 15 | now exiting' |
while read -r line ; do
case "$line" in
"got signal 15")
echo "hi"
;;
"now exiting")
echo "hi2"
;;
*)
esac
done
The problem is tail is not working here , whenever the new log details added its not going to the case statement and echos the output I could get the output if i use cat/less/more Could you someone please tell what mistake i have done here ?
|
The tail issue that habitual pointed out would be a good start, but using logwatch or another such utility would be the best bet here. It's written/designed specifically to look at log files for patterns. Also, do you have any systems monitoring in place now? Because things like zabbix/nagios can ALSO be used to watch log files, and act accordingly.
There are also LOTS of already-written shell scripts to watch a log..you can find these with a brief Google search. I'd suspect there's an issue with your case statements/code there, but given the many options that already exist to do this, I'd use those.