Skip to content

Instantly share code, notes, and snippets.

@solidsnack
Created September 6, 2017 17:05
Show Gist options
  • Save solidsnack/ba960c84ffee567083f1bcba0851f183 to your computer and use it in GitHub Desktop.
Save solidsnack/ba960c84ffee567083f1bcba0851f183 to your computer and use it in GitHub Desktop.
Cron as a tiny shell script (GNU tools required)
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