[olug] Handy script...

Dan Linder dan at linder.org
Mon Jan 18 10:25:00 CST 2016


Last week I needed to start a process at a specific time but at/cron didn't
cut it, and it needed to be fairly OS agnostic.  I came up with a simple
"sleepuntil" script with a bit of help from StackExchange and other online
sources:

#!/bin/sh
WAKE="\"$*\""
SECONDS=$(( $(date -d "$*" +%s) - $(date +%s) ))
HMS=$(date -u -d @${SECONDS} +"%T")
echo Sleeping until ${WAKE}, HMS=${HMS}, or ${SECONDS} seconds.
sleep ${SECONDS}


Then I run it like this:

$ sleepuntil 14:25 ; /path/to/my_command


I also use the "screen" command to keep terminal sessions active, so even
if my connection is terminated before the sleepuntil command kicks off it
will still complete and let the "my_command" program run.

Just my $0.02 worth...

Dan

-- 
***************** ************* *********** ******* ***** *** **
"If a problem has no solution, it may not be a problem,
  but a fact - not to be solved, but to be coped with
  over time." - Shimon Peres

"Quis custodiet ipsos custodes?"
    (Who can watch the watchmen?)
    -- from the Satires of Juvenal

"I do not fear computers, I fear the lack of them."
    -- Isaac Asimov (Author)
** *** ***** ******* *********** ************* *****************


More information about the OLUG mailing list