Results 1 to 1 of 1
Dont know how best to word this other than I'm looking for the ability to set a timer, throw it in the background and then cancel it if some other ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-16-2012 #1
- Join Date
- Oct 2012
How, sleep timer that can be cancelled? Countdown with push back
while true; do if [ $event == "match" ] then #do something to kill any previous sleeps from this loop <code> #<<need help here #set a new sleep as of now (sleep 300; echo "action";) & fi done
The idea in a way is to have an idle timer (kind of) that basically keeps pushing back the deadline until the event hasn't actually been seen for a full 5 minutes. If that event has been seen within that 5 minutes count down, push it back, reset the count down... start over.
The reason why this sleep has to be in the background is it can't be blocking that while loop.
I wont be shocked for a second if there's a much better way to look at this other than what I have proposed. Sleep probably isn't the best way to handle this.
On another thread for a similar topic someone proposed piping one loop into another. And instead of a sleep timer compare timestamps
(while read line; do echo "time"; done) | while read action; #compare new time to previous time.. , perform action
Makes sense to me but not quite working as expected. I welcome other thoughts. I want to be able to do this for multiple events/strings and have different actions depending on the input string. I was starting to think maybe I need an in memory key-value pair. One script to update those keys and one script to iterate through them every minute. Not sure what the best solution for that idea is... memcache comes to mind but seems a bit over kill. I could even just use regular old sql, but once again seems over kill and hits disk.