send mail once string is seen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting send mail once string is seen
# 8  
Old 05-16-2006
Here's where you begin, but still, there are more things to consider...

ERROR=$(grep ORA-12157 /your/log/file.txt | wc -l)
if (( ${ERROR} > 0 )); then
mailx -s "SQLException: ORA-12157: TNS:internal network communication error" \ <email alias for multiple users>
fi

Save that in a script and put it in your cron tab.
Create a mail group in sendmail, and that's that.
That'll do what you are asking

BUTthere are other considerations.
Do you want to send the email every time the error occurs?
Are you just checking every so often, like say, every day to see if such error occured?
How often does the log file rotate? You don't want to be sending multiple e-mails for a single event, right?
# 9  
Old 05-17-2006
Quote:
Originally Posted by System Shock
Here's where you begin, but still, there are more things to consider...

ERROR=$(grep ORA-12157 /your/log/file.txt | wc -l)
if (( ${ERROR} > 0 )); then
mailx -s "SQLException: ORA-12157: TNS:internal network communication error" \ <email alias for multiple users>
fi

Save that in a script and put it in your cron tab.
Create a mail group in sendmail, and that's that.
That'll do what you are asking

BUTthere are other considerations.
Do you want to send the email every time the error occurs?
Are you just checking every so often, like say, every day to see if such error occured?
How often does the log file rotate? You don't want to be sending multiple e-mails for a single event, right?
I gave this my own shot

# vi check_ora
"check_ora" 14 lines, 302 characters
#program to grep orac error and email admin
#5-15-06
#Chris Saunders

if grep ORA-12157 /u01/AIDMS/log/AIDMS_default_island_1/aidms.log
then

echo "Oracle issues on cluster" | mailx -s "SQLException: ORA-12157: TNS:internal network communication error" saundersc
@hostname

fi

echo $?

but i cant get the email. this is just a starting point... i posted in the solaris forum on why i cant receive the email...
# 10  
Old 05-17-2006
Quote:
Originally Posted by System Shock
Here's where you begin, but still, there are more things to consider...

ERROR=$(grep ORA-12157 /your/log/file.txt | wc -l)
if (( ${ERROR} > 0 )); then
mailx -s "SQLException: ORA-12157: TNS:internal network communication error" \ <email alias for multiple users>
fi

Save that in a script and put it in your cron tab.
Create a mail group in sendmail, and that's that.
That'll do what you are asking

BUTthere are other considerations.
Do you want to send the email every time the error occurs?
Are you just checking every so often, like say, every day to see if such error occured?
How often does the log file rotate? You don't want to be sending multiple e-mails for a single event, right?
i want to send the email everytime it occurs on the current days date.. so I dont get an email from an old error...

the log file does not rotate often

i want this to run every 30 seconds... but i know how to do that via cron..
# 11  
Old 05-17-2006
Quote:
Originally Posted by csaunders
I gave this my own shot

# vi check_ora
"check_ora" 14 lines, 302 characters
#program to grep orac error and email admin
#5-15-06
#Chris Saunders

if grep ORA-12157 /u01/AIDMS/log/AIDMS_default_island_1/aidms.log
then

echo "Oracle issues on cluster" | mailx -s "SQLException: ORA-12157: TNS:internal network communication error" saundersc
@hostname

fi

echo $?

but i cant get the email. this is just a starting point... i posted in the solaris forum on why i cant receive the email...
You are not getting anything because your "if" statement has no validation.
In layman's terms, your statement reads:
"if I look in this file for this information, then..."
It should read:
"if I look in this file for this information AND I find it, then..."

The snippet that I posted before should work. Obvioulsy is not the solution, since you want to get an e-mail every time you get the alarm, and the snippet I posted will e-mail you as long as there is 1 entry anywhere in your log file.

Now, are the entries in your log file time stamped?
# 12  
Old 05-17-2006
Quote:
Originally Posted by System Shock
You are not getting anything because your "if" statement has no validation.
In layman's terms, your statement reads:
"if I look in this file for this information, then..."
It should read:
"if I look in this file for this information AND I find it, then..."

The snippet that I posted before should work. Obvioulsy is not the solution, since you want to get an e-mail every time you get the alarm, and the snippet I posted will e-mail you as long as there is 1 entry anywhere in your log file.

Now, are the entries in your log file time stamped?
yes there is a time stamp in this format, 2006-05-08 16:09:59,734

but i have to disagree with you, my program seems to be working...

if i dont echo the body of the text to mailx, then it waits for me to type it, once i run the script.... therefore im thinking the grep executes and finds that string and executes the then...
# 13  
Old 05-17-2006
What shells are available? A quick, non-robust solution in ksh / pdksh might be as follows:
Code:
#! /bin/ksh
file=/u01/AIDMS/log/AIDMS_default_island_1/aidms.log

tail -n0 -f $file |&
while read -p line; do [[ $line == *ORA-12157* ]] && {
  print $line # To stdout
  mail_code_goes_here
 }
done

This will follow the file (tail -f), so it only counts messages received while it's running, so you'll have to find a way to make sure it runs reliably (if this is just a band-aid, nohup might be good enough.)

HTH
# 14  
Old 05-18-2006
Quote:
Originally Posted by System Shock
You are not getting anything because your "if" statement has no validation.
In layman's terms, your statement reads:
"if I look in this file for this information, then..."
It should read:
"if I look in this file for this information AND I find it, then..."

The snippet that I posted before should work. Obvioulsy is not the solution, since you want to get an e-mail every time you get the alarm, and the snippet I posted will e-mail you as long as there is 1 entry anywhere in your log file.

Now, are the entries in your log file time stamped?

There is nothing wrong with code like:
if grep string filename ; then echo string was found ; fi

grep sets its exit code to indicate whether or not it found anything. Output may be sent to stdout which is the only concern. Usually you would use -q or redirect the output to /dev/null.

if grep string filename >/dev/null ; then echo string was found ; fi
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

Search the string in the active log and send mail

Hello, I wanted to search specific string in the acitve log file and send an email if the search string found in the log. Log file is written by application all the time. So, script has to search if any new log entry has the specific string for example " sample exception" and send an email. (1 Reply)
Discussion started by: balareddy
1 Replies

3. Ubuntu

Not able to send mail out of UbuntuBox in send mail

Hi Guys.. yesterday i purchased a VPS server and installed sendmail on ubuntu 12.4 with Webmin & Apache runing webserver problem is.. i can send mail via webmin user interface account to anybody to out side to any domain and able to recieve any mail from any domain.. Now main... (2 Replies)
Discussion started by: cmdman
2 Replies

4. Shell Programming and Scripting

How to send mail using PHP mail function On apache server.?

Hello, I am using centos-6.2 I have apache server,php5 on my system and I want to send mail using sendmail on my system. when I try to send mail from shell that time mail is succesfully sent to respective address() but when I try to send it through webbrowser I am not able to send it.... (1 Reply)
Discussion started by: Kiran ursal
1 Replies

5. UNIX for Advanced & Expert Users

How can I send a mail from my outlook or other mail accounts to UNIX server?

Hi all, I want to send a mail for my business needs from outlook account to an unix server (HP-UX) but I don't send any mail. While I can send from the unix server to my outlook account, I can't send from outlook to unix. How can I achieve this ? How can I send a mail from my outlook or other... (2 Replies)
Discussion started by: igelegin
2 Replies

6. 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

7. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

8. UNIX for Advanced & Expert Users

send attachments using send mail in Solaris

Hi All, I have a requirement to send and email of body html with an attachment. concatinating uuencode output to the mail body with mailx command works, but as my Email body is of HTML type i use sendmail. my command to send HTML body is as below: export MAILTO="recipient@domain.com"... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

9. Shell Programming and Scripting

Search for string and send mail

Hi, I need to find if there is any error in the last few lines of the log file and send a mail accordingly.For example, Following errors can be logged in the log file. ERR_1="DB Connection not established" ERR_2="Server Unloading" I need to find if these errors are found in the log file and... (1 Reply)
Discussion started by: AnneAnne
1 Replies

10. UNIX for Dummies Questions & Answers

can not send mail from unix server to company/yahoo mail

hi, Gurus, I need some help with sending mail out from my UNIX server: It is running Solaris 2.6 and the sendmail version is 8.8. Output of :/usr/lib/sendmail -d0.1 -bt < /dev/null Version 8.8.8+Sun Compiled with: LOG MATCHGECOS MIME7TO8 MIME8TO7 NAMED_BIND NDBM NETINET ... (5 Replies)
Discussion started by: b5fnpct
5 Replies
Login or Register to Ask a Question