Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 11-02-2004, 01:39 PM   #1
LQ Newbie
Registered: Nov 2004
Posts: 2

Rep: Reputation: 0
Bash script to alert by email 3 times then stop.


I've written a bash script that will alert me via email(or email my pager) when the mail queue on my anti-spam/virus server gets above a certain threshold.
Currently if my mail server goes down(the next hop after the anti-virus server) then the mail will queue on the anti-virus server until my mailserver comes back online.
I have set this script to run from the crontab every 15 minutes and log the output to a file.
This has been working great but one day i took my mail server down for maintainace and eventually was alerted via pager that my mailqueue had reached the threshold. I noticed that it will continue to alert me until the queue drops down(in this case i received 20 of them...a bit annoying)

What I am looking to do is bascially receive the notification email 5 cycles before it stops notifying me while the condition exists. Then when the mail queue shrinks below my number(in this case 250) it will alert me that the queue is back down.

I've been wracking my brain and needed some scripting help with this. I don't know if there is a way to set a variable in the script that will stay active after it's done being run. (So do some sort of if # < 5 alert me, else don't)
That's where i seem to be stuck. Don't know if i should use a counter, touch a file then delete it, or what...i'm just kinda lost at this point.

Anyone have any ideas on how to do this?
Old 11-03-2004, 12:17 PM   #2
LQ 5k Club
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,105

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Maybe there is an easier way, but you could try putting your "variable" into a file.
An example: I turn my computer on and off as and when I need it, maybe several times a day.
I use ntpdate to sync my local time. I do not want to do this every boot-time, just once a day. I also wanted to play with cron. So cron calls this script once an hour:
# No need to check the time more than once a day,
# no matter how often this script is called by cron
NOW=`date | cut -b 1-10`
LAST=`cat /etc/.lasttimecheck`
if [ "$NOW" != "$LAST" ]; then
	echo $NOW > /etc/.lasttimecheck
My "variable" is the date the time was last checked. It is held in the file .lasttimecheck. If that is not today, the time is checked, and the file is updated.

Hope this helps.
Old 11-04-2004, 07:23 AM   #3
LQ Newbie
Registered: Nov 2004
Posts: 2

Original Poster
Rep: Reputation: 0

That definitly did it.
I guess my brain was so fried that i didn't think of setting a variable equal to a file.
The line that definitly helped me was

LAST=`cat /etc/.lasttimecheck`
Guess i was overthinking the solution.

I thank you very much for you will make my week much easier now..


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: run a script at most 3 times simultanously paterijk Programming 4 08-18-2005 02:49 PM
Write a script to send an email from bash kpelczar Linux - Software 5 02-09-2005 04:19 PM
bash script to email updated ip ericnmu Linux - Networking 1 10-01-2004 10:30 PM
bash script to stop isdn service after x mintus? paul.nel Programming 4 03-11-2004 10:01 AM
bash script, parsing email addresses kepler Programming 6 01-26-2004 06:47 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration