I am searching for some logic which will help me to introduce quick action for the errors. We have application server and we need to check the bunch of information for every 10 minutes and alert thru mail. I wrote a script in which i am tailing last 1000 lines and counting one exception then sending mail like below
count=`tail -n 2000 /logsTrace.log | grep -c 'TimeOutException'`
if [ $count -ne 0 ]
then
echo "Error! $server is thrown TimeOutException $(date +"%D %T")" >> temp.txt
cat temp.txt | mail -s "Error! $server is thrown TimeOutException $(date +"%D %T")" $mail_id
i need to change my logic with the awk command where i can take like this for all exception tailing at one time
like wise i can add for all the exception by tailing one time the log so that i can minimize the use of tailing. But how do i can send mail. Is there any way to do this please help me. i am stuck in that.
But i am looking for a script which can send a mail with some messages, for example if the OOM is 1 then its send a message that we got the Out of Memory if the Jms =1 then i need to send the message like Time out exception... Do i can use more if loop and user the outside variable mail id in the awk ..?
Same like i need to check in the systemut.log and systemerr.log log.. do i make this as a function and reuse it more often.
Perhaps you are thinking in a too complicated way? If I understood your problem correctly, main thing is to receive e-mail in case of an error, not for collecting statistics every 10 minutes?
Why wouldn't you just do something like
tail -f message_log_file | \
awk '/OOM/ { printf "OOM" }
/JAM/ { printf "JAM" } ' | while read LINE
do
# and the mailing part comes here
done
(Or even faster, use sed's regexps).
I haven't tested that, but it should work - and is LOTS lighter than polling the last 2000 lines of a file. Plus, this informs you instantly (well, one second after the file is changed, to be precise).
But my requirement is modifying the cron job which is already running there for a ten minutes. I need to tune the script to obtain more accuracy. The earlier script is very huge and they use tail -2000 for each every exception. We have almost 21 exception to catch and they are doing tail -2000 21 times for the same log. I thought of modifiying it awk statement and asking for help. Jim has given a hint to my idea but still i need some clarification on the mailing parts. In your logic if i get two exception i will get same mail not different mail. still i am require your expertise on this.
OK, you didn't mention about the cron job earlier :-(
Then we should go back to Jim's drawing board.
This way you'll receive one e-mail per each exception. The idea is to use the fact that all arrays in awk are assosiative, ie. indexed by strings. You can also group the matches, like
but the code may get difficult to read.
pen
Last edited by pen; 04-06-2009 at 07:31 PM..
Reason: Prettyprinted the code
But if i need add some lines and not only the exception then how can i add that and how i decide about the subject line of the mail content. I will be common for all the exception and not specific. I asked the same query to Jim also. I know i am expecting more, but that way we give a good script.
Hi,
I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern.
Note:These are the samples of two files,but i can have more... (2 Replies)