BashScripts.org
http://bashscripts.org/forum/

Need help in Bash script on Time entries
http://bashscripts.org/forum/viewtopic.php?f=16&t=875
Page 1 of 1

Author:  man-nux [ Mon Aug 24, 2009 11:43 am ]
Post subject:  Need help in Bash script on Time entries

Hey there...

Need some help in bash scripting where I need to write code which will actually count minutes and seconds. Just like after some specific minute do the task or wait for some minutes/seconds before executing the command?
My script is polling data for concurrent number of sessions and if that crosses above threshold in my case its 100. it should send mail but whats happening here is since the polling is happening at every 5 mins and it threshold is being crossed regularly mail is forwarded every 5 min, this is what I wanted to avoid.

it goes something like this

threshold=``snmpwalk -Of -On -v 2c 1.1.1.1 -c xxxxx 1.3.6.1.4.1.12532.12 | awk '{print $NF}'`


if [ $threshold -gt 100 ];then
mail -s "Threshold crossed" [email protected]
sleep 30m
else
echo "Looks Good"
fi

crontab entry is to poll the device for every 5 min.

Please advise.

Author:  Watael [ Tue Aug 25, 2009 12:44 am ]
Post subject:  Re: Need help in Bash script on Time entries

May I say it's non-sense (and not the funny way) to schedule a task that override the scheduling time of a script:

having in a cron, every 5 minutes, a task to make it sleep for more than these 5 min. (in your script 30mn), is in depth stupid!

it's not bash logical, it's just common sense...


or, did you miss some explanation...that could make sense?

Author:  thobbs [ Mon Aug 31, 2009 12:27 am ]
Post subject:  Re: Need help in Bash script on Time entries

You should just use some logic and reverse your conditions here.

Have cron run the script every 30 minutes.

If you don't cross the threshold, sleep 5 minutes and retry; put this in a loop that will run 5 times. This covers 25 minutes.

If you do cross the threshold, send the mail and exit. It will be 30 minutes before cron runs the script again.

I think you can handle writing the code just fine.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com