Issue
A little background first: We have 9 JVM servers that are outputting log files that I am parsing constantly to find when an error occurs. The logs roll every 5-10 minutes, but the file name does not change. I was using SupperPutty to open 9 sessions and run the below script against each log file, but this was only affective when I was at work.
tail -f *filename* | nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=2 a=4 s="Bind value for HASCHILDREN = 0"
So I wanted to turn the above script into a background script that would email me when an error occured. I first had to KSH into a second shell to avoid stopping the scripts when I exited (even when I set them up as NOHUP). I tried setting up the script as below, but it doesn't email me when the error occurs.
tail -f *filename* | nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=2 a=4 s="Bind value for HASCHILDREN = 0" | mailx -s "Childrens flag has been detected" *email* &
Any help would be greatly appreciated.
Solution
You could try to schedule a cron job in the crontab file to call a script every 5-10 minutes that checks for any changes in your logs and sends you an email if an error entry is found.
From the crontab documentation:
The crontab command invokes an editing session that allows you to create a crontab file. You create entries for each cron job in this file. Each entry must be in a form acceptable to the cron daemon. For information on creating entries, see The crontab File Entry Format.
Exanple:
To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:
30 6 * * 1,3,5 /usr/bin/calendar
Alternatively, you can create a crontab file by specifying the File parameter. If the file exists, it must be in the format the cron daemon expects.
Answered By - nay743 Answer Checked By - Clifford M. (WPSolving Volunteer)