Register
It is currently Sat Nov 22, 2014 4:28 am

Need help in Bash script on Time entries


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Aug 24, 2009 11:43 am   

Joined: Mon Aug 24, 2009 11:39 am
Posts: 1
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" abcd@abcd.net
sleep 30m
else
echo "Looks Good"
fi

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

Please advise.


Top
 Profile  
 PostPosted: Tue Aug 25, 2009 12:44 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 567
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?


Top
 Profile  
 PostPosted: Mon Aug 31, 2009 12:27 am   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
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.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP