I want my script to NOT to send an e-mail if it finds the same keyword more than twice.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I want my script to NOT to send an e-mail if it finds the same keyword more than twice.
# 1  
Old 11-26-2014
Question I want my script to NOT to send an e-mail if it finds the same keyword more than twice.

My script triggers and e-mail if keywords supplied to it were found.
Problem is if it find the same keyword continously (due to continous server errors), it triggers mails and fillup my mail box with same message (which is not required)
I want my script to NOT to send an e-mail if it finds the same keyword more than twice.

Following is my script
Code:
#!/bin/sh
TOTAL_LINES=0
DELTA=0
ERR=0
LINE_NO=`cat /sybase/B10/temp.txt`
echo $LINE_NO
TOTAL_LINES=`more /sybase/B10/ASE-15_0/install/B10.log | wc -l`
echo $TOTAL_LINES
DELTA=`expr $TOTAL_LINES - $LINE_NO`
echo $DELTA
ERR=`tail -$DELTA /sybase/B10/ASE-15_0/install/B10.log | egrep -i "infected|signal|error|warning|severity|fail|suspect|corrupt|deadlock|critical|problem|threshold|NO_LOG|logsegment|stacktrace|encountered"| grep -v "background task error"|wc -l`
echo $ERR
if [ "ERR" -gt 0 ]; then
 tail -$DELTA  /sybase/B10/ASE-15_0/install/B10.log  | egrep -i "infected|signal|error|severity|fail|suspect|corrupt|deadlock|critical|problem|threshold|NO_LOG|logsegment|stacktrace"| grep -v "background task error" | mailx -s "Errors found in B10.log. Pls check" rajeshneemkar@gmail.com
rm /sybase/B10/temp.txt
echo "$TOTAL_LINES" >/sybase/B10/temp.txt"
fi

Any help in this regards is highly appreciated
Best Regards,
Rajesh

Last edited by Don Cragun; 11-26-2014 at 09:44 AM.. Reason: Add CODE tags.
# 2  
Old 11-26-2014
Just to clarify the purpose of the script - this script is run periodically (via cron?), and when it runs, it looks for keywords in the "new" part of the logfile (what was appended since the last time you ran the file), and finding them, is supposed to send you one email?

---------- Post updated at 08:54 AM ---------- Previous update was at 08:52 AM ----------

And by "finds the keyword twice", do you mean you've gotten more than two emails for the same keyword? Or for any of the keywords? What would clear the condition - not finding the error when the script is run?
# 3  
Old 11-26-2014
Yes, the script is run via CRON (every minute)
Yes, it looks for keyword from the "new" part of log file
Yes, I received more than 500 same e-mail, when the same error occured more than 500 times
No of e-mails is proportional to no of (same)error messages, whihc i dont want. (I want only one e-mail if the error is recurring)

Thanks
Rajesh

---------- Post updated at 09:41 AM ---------- Previous update was at 09:23 AM ----------

Consider the following situation
Code:
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531

I receive an 4 e-mails if the same error is repeating.
Now imagine the situation with 500 errors (same and continous)

What I'm looking at is, if the script detects the same error as detected earlier (due to continous errors generated by the server), it should not send me an e-mail for the second time. Just one e-mail is enough.

This is just to stop inbox full situation

Last edited by zaxxon; 11-26-2014 at 11:04 AM.. Reason: code tags
# 4  
Old 11-26-2014
The thread is not AIX specific (moving it) and please continue to use code tags, thanks.
# 5  
Old 11-26-2014
I may be misunderstanding your requirements but wouldn't:-
  1. create a log of emails sent
  2. match lines your "new" part of the source log to to the email log
  3. on no hit send an email and append the emails sent log else get the next line
be simpler?

Last edited by rbatte1; 11-26-2014 at 01:29 PM.. Reason: Added LIST=1 tags
# 6  
Old 11-26-2014
Quote:
Originally Posted by Rajeshneemkar
Yes, the script is run via CRON (every minute)
Yes, it looks for keyword from the "new" part of log file
Yes, I received more than 500 same e-mail, when the same error occured more than 500 times
No of e-mails is proportional to no of (same)error messages, whihc i dont want. (I want only one e-mail if the error is recurring)

Thanks
Rajesh

---------- Post updated at 09:41 AM ---------- Previous update was at 09:23 AM ----------

Consider the following situation
Code:
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531
JS: js__callout: Not yet time for sjobid 137, calloutid 471531

I receive an 4 e-mails if the same error is repeating.
Now imagine the situation with 500 errors (same and continous)

What I'm looking at is, if the script detects the same error as detected earlier (due to continous errors generated by the server), it should not send me an e-mail for the second time. Just one e-mail is enough.

This is just to stop inbox full situation
I guess I still don't understand your requirements. You show four lines above and say you only want one message for those four lines (not four messages), but none of the keywords in either of the egrep commands in your script are in those four lines. So, why should any message be sent?

Let me see if I understand what you're trying to do. You're running your log processor every minute, and you're only looking at new messages in the log file each minute. So, are you saying you want a mail message each minute of the day in which that error is reported? With the sixteen keywords in your 1st egrep (there are only fourteen in the 2nd egrep) do I correctly understand that you're OK getting 16 messages each minute for each minute of the day (for a maximum of 23,040 messages in your mailbox each day) as long as no two messages sent by any invocation of your log checker contain the same keyword? Are the lines that you show above supposed to generate mail messages or not? (As I said before, none of your keywords are present in those lines.)

Why are you counting sixteen keywords as errors but only sending e-mail for fourteen of those keywords?
# 7  
Old 11-26-2014
Are the lines really that completely identical? You can just remove duplicates:

Code:
awk '! ($0 in A) { A[$0] ; print }' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Ksh: Send a mail in case grep finds something

I want to search a file if it contains special strings and if yes, the records found should be mailed. I can either do it with a temporary file: /usr/bin/grep somestring somefile > /tmp/tempfile && /usr/bin/mail -s "Found something" email@mycomp.com < /tmp/tempfile... or by running the grep... (10 Replies)
Discussion started by: Cochise
10 Replies

4. Shell Programming and Scripting

Script Contain Send Mail via Telnet

Dear Masters, I am using Solaris 10 and bash shell. I make a script for checking if a file is exists on the specified folder or not from 5th day of the month until the end of the month. If the file doesn't exist, the script will send email to me. The script ran perfectly when I execute it on... (6 Replies)
Discussion started by: kris.adrianto
6 Replies

5. Shell Programming and Scripting

not able to send the mail through perl script

I have written small piece of code to send mail through perl script.Below is the code.I have executed it as # perl perlmail.pl and the code got executed with no errors. Still have not received any mail. Also I have installed Mail::send module from CPAN directly but no luck. Could any mail... (2 Replies)
Discussion started by: giridhar276
2 Replies

6. Shell Programming and Scripting

script to send mail !!

Hi Experts.. i have created a table with the fields, empid name mailid 1 raja raja@xy.com and entered the values of all persons who are in that file... i have a .csv file date shift1 shift2 6/6/2011 ram raja Now i want a script that could fetch the data in (input file .csv file) and... (3 Replies)
Discussion started by: cratercrabs
3 Replies

7. Shell Programming and Scripting

Help-send mail script

Hi, I have written one script for sending mails with attachment. currently its working for only one recipient. I want to send mails to n number of users by taking user input i.e number of users. Output of current script: Enter how many files : 1 Enter First Name : kiran E-Mail... (2 Replies)
Discussion started by: kiran_j
2 Replies

8. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

9. Shell Programming and Scripting

Script to send a mail in UNIX

Hi, I need to write one unix script gor sending a mail notification. I have to pass the followinf as arguments,from ,to,subject,messege body Can i use mailx....Please provide the code Thanks in advance. (1 Reply)
Discussion started by: sudhi
1 Replies

10. Shell Programming and Scripting

Send e-mail in Shell script

How to send an error mail from a shell script e.g. mail destination_adr@blabla.int "Message : here an error message " thanks, Ann. (1 Reply)
Discussion started by: annelisa
1 Replies
Login or Register to Ask a Question