Skip to content

Instantly share code, notes, and snippets.

@skarllot
Last active June 3, 2019 06:39
Show Gist options
  • Save skarllot/5874363 to your computer and use it in GitHub Desktop.
Save skarllot/5874363 to your computer and use it in GitHub Desktop.
Bash wrapper for cron to run any script daily, weekly and monthly.
#!/bin/bash
# Called by cron: 0 0 * * * /root/scripts/cron-weekly.sh "/myscript.sh"
# "/myscript.sh" should handle "monthly", "weekly" and "daily" parameters.
wkdate=`date +%w`
DD=`date +%d`
# Mon - Fri, & Sun run daily
# Saturday run weekly except:
# the 1st Saturday of each month run monthly
case $wkdate in
6)
if [[ $DD -lt 8 ]] ; then
# Run monthly
eval "$1 monthly"
else
# Run weekly
eval "$1 weekly"
fi
;;
*)
# Run daily
eval "$1 daily"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment