-
-
Save sisso/23e3b6903f61c0c4df55862abc83ba77 to your computer and use it in GitHub Desktop.
crab script ro run things daily one hour after the computer boot, just once a day. You need run this on user cron on every hour
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 | |
set -euo pipefail | |
# set -x | |
dir="${HOME}/.daily-scheduler" | |
log="${dir}/log" | |
mkdir -p "${dir}" | |
now=$(date -I) | |
log() | |
{ | |
echo "$*" >> "${log}" | |
} | |
if grep -aq "$now complete" "${log}"; then | |
# log "$now already executed, ignoring" | |
true | |
else | |
if grep -aq "$now scheduled" "${log}"; then | |
# check if is current time | |
next="$(grep -oaP "$now scheduled \K\d+" "${log}")" | |
hour="$(date +%-H)" | |
if [[ hour -ge next ]]; then | |
log "$now running" | |
$* | |
log "$now complete" | |
else | |
log "$now waiting for ${next}" | |
fi | |
else | |
# schedule next hour | |
hour=$(($(date +%-H) + 1)) | |
log "$now scheduled $hour" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment