Stop sending mail after certain number of mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stop sending mail after certain number of mail
# 1  
Old 10-26-2010
Stop sending mail after certain number of mail

Hi guys...

I am busy writing a script to notify me via an mail if my application is down. I have done that.

Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application.

When the application is up again that count should be cleared.

Please help!!!!!!!!!!!!!!!!!!!!
# 2  
Old 10-26-2010
Write that count into a temporary file with a redirection of an echo for example and check it every time the script is started and noticed an error. When an error is detected, increment it's content by 1. When it's content reaches 5, continue but do not enter the branch to send a mail anymore.
When the application is up again, let the script echo a 0 or 1 into that temporary counter file.
# 3  
Old 10-26-2010
Thanks for the reply...

I don't do scripting most of the time...

Can you please show me some hint in terms of commands...

Thanks a lot for the help!!!!!!!!
# 4  
Old 10-26-2010
Assuming ksh, but probably very similar in other shells:-

Code:
if <whatever your condition is>
then
   ((i=`cat statusfile`+1))
   echo $i > statusfile
   if [ $i -le 5 ]
   then
       sendmail commands here
   fi
else
   echo 0 > statusfile     # Make sure there is a space after the zero
fi


Does that help?



Robin

Last edited by Scott; 10-26-2010 at 08:47 AM.. Reason: Code tags, please...
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 10-26-2010
Thanks a million times...

This will help a lot...



---------- Post updated at 04:06 PM ---------- Previous update was at 02:46 PM ----------




One quick question. I want this script to send mail to different group of people. That is if it is during business hours (i.e. 8H00 am and 18H00 pm to certain group and after hours to another group)...

How can I achieve this?

Last edited by Phuti; 10-27-2010 at 03:50 AM..
# 6  
Old 11-15-2010
The second question

Phuti,

Sorry for the delay, I have been away.

A simple test on the system clock should help. You could insert the following:-
Code:
if <whatever your condition is>
then
   ((i=`cat statusfile`+1))
   echo $i > statusfile
   if [ $i -le 5 ]
   then
       if [ `date +%H` -ge 8 -a `date +%H` -lt 18 ]
       then
          sendtolist="aaa@abc.com; bbb@abc.com; ccc@abc.com"
       else
          sendtolist="xxx@abc.com; yyy@abc.com; zzz@abc.com"
       fi
       sendmail commands here using $sendtolist
   fi
else
   echo 0 > statusfile     # Make sure there is a space after the zero
fi

I hope that this helps you a bit more.



Robin
Blackburn/Liverpool
UK
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. Red Hat

Problems sending mail: Difference between Mail and Mailx?

Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL) ... (1 Reply)
Discussion started by: RedSpyder
1 Replies

3. Shell Programming and Scripting

Sending Mail

Hi All, I have a script that looks like this: *********** #!/bin/sh -x cd /u01/app/oracle/diag/rdbms/spdb/spdb/trace cat alert_spdb.log|grep Archiver >/dev/null if ; then mailx -s "Archiver message in Alert log" user@email.com fi ************ Im using the -x option to see any... (1 Reply)
Discussion started by: oradba888
1 Replies

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

5. Shell Programming and Scripting

Sending mail

Hi there, How can I send the automated log file, daily at 7 am to the respective mail . Thanks in Advance, Neha (2 Replies)
Discussion started by: NehaKrish
2 Replies

6. UNIX for Dummies Questions & Answers

sending mail

i want to send an email from the unix machine to the windows machine. now windows dont have any specified folder for the mail. mail has to be sent to the email-id like abc@xyz.com unix machine itself can not directly send mail. it has to be transferred via mail server. (11 Replies)
Discussion started by: parmeet
11 Replies

7. Solaris

how to forward mail in /var/mail/username to external mail

Dear All, Now I use solaris 10 and I try to forward mail from /var/mail/username to their external mail so what should I do? thank u in advance (2 Replies)
Discussion started by: unitipon
2 Replies

8. Shell Programming and Scripting

Mail sending

Dear all, how can i send mail using mailx or mail command?do i need to configure anything for sending mail?please help me.Its urgent. the version i use is Linux TDM 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686 i686 i386 GNU/Linux Thanks Regards, Pankaj (15 Replies)
Discussion started by: panknil
15 Replies

9. UNIX for Dummies Questions & Answers

Sending Mail

Please help me out i want to know how to send email from unix machine to any email-id. mail to be sent is web based mail. (1 Reply)
Discussion started by: parmeet
1 Replies

10. UNIX for Dummies Questions & Answers

sending a mail to a mail client

Hi everyone! I'm trying to create a database monitoring script that reads an alert file and sends an error message if it can 'grep' a particular string. Is there a way to send this message to a mail client using SMTP? Even better, is there any place on this site that has these kinds of... (5 Replies)
Discussion started by: solaris73
5 Replies
Login or Register to Ask a Question