Last active
June 3, 2019 06:39
-
-
Save skarllot/5874363 to your computer and use it in GitHub Desktop.
Bash wrapper for cron to run any script daily, weekly and monthly.
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 | |
# 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