Created
May 29, 2013 06:11
-
-
Save ekimekim/5668278 to your computer and use it in GitHub Desktop.
Run a command at a certain time.
Simpler than at(1) - it creates a background job in the current shell environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -lt 2 ]; then | |
echo "USAGE: $0 TIME COMMAND {ARGS}" | |
echo "Run COMMAND with ARGS at specified TIME." | |
echo "TIME may be given in any form understood by date(1)" | |
exit 2 | |
fi | |
duestr="$1" | |
shift | |
due=`date -d "$duestr" +%s` | |
if [ ! "$due" ]; then | |
echo "Error: Could not understand due time." | |
exit 1 | |
fi | |
now=`date +%s` | |
interval=$((due - now)) | |
if [ "$interval" -lt 0 ]; then | |
echo "Error: $durstr is $((-interval))s in the past." | |
exit 1 | |
fi | |
( sleep "$interval" && "$@" ) & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment