Created
September 6, 2017 17:05
-
-
Save solidsnack/ba960c84ffee567083f1bcba0851f183 to your computer and use it in GitHub Desktop.
Cron as a tiny shell script (GNU tools required)
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
function minicron {( | |
set -o errexit -o pipefail -o nounset | |
spec="$1" ; shift | |
cmd=( "$@" ) | |
present="$(date -u +%FT%TZ)" | |
target="$(date -u +%F)T$spec:00Z" | |
next_target="$(date -u -d tomorrow +%F)T$spec:00Z" | |
if [[ $present > $target ]] | |
then target="$next_target" | |
fi | |
echo "Awaiting: $target" >&2 | |
while sleep 60 | |
do | |
present="$(date -u +%FT%TZ)" | |
if [[ $present > $target ]] | |
then | |
next_target="$(date -u -d tomorrow +%F)T$spec:00Z" | |
if ("${cmd[@]}") | |
then | |
target="$next_target" | |
echo "Awaiting: $target" >&2 | |
fi | |
fi | |
done | |
)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment