DAY_OF_MONTH(1) User Manuals DAY_OF_MONTH(1) NAME day_of_month - check, if an date is the N day of the month and run a as parameter given program. Where day is one of Monday to Sunday. SYNOPSIS day_of_month [ --help | 1 | 2 | 3 | 4 | 5 ] PROGRAM DESCRIPTION day_of_month is mainly for the use in crontab files. It allows an easy way to check, if the day you run your cron job is the N day of the month. If it is the given day, it starts PROGRAM. PROGRAM is any executable file. If you will give parameters to your program, your invoking must be quoted. EXAMPLES run a program at 16:05 on each second Saturday of a month, your crontab may look like: 16 05 * * 6 day_of_month 2 "program parameter1 parameter2 ... " OPTIONS -h print this help AUTHOR Wulf Coulmann <scripts at gpl.coulmann dot de> SEE ALSO crontab(1) Linux Last change: August 2006
#!/bin/bash # copyright Wulf Coulmann <scripts at gpl.coulmann dot de> # GNU GPL # http://www.gnu.org/licenses/gpl.html # # Download me here: http://gpl.coulmann.de/day_of_month # ------------------------------------------------------------------------ USAGE=" Usage: day_of_month [ --help | 1 | 2 | 3 | 4 | 5 ] PROGRAM" PROG=$2 function run_prog () { if [ ${#PROG} -gt 0 ] ; then $PROG else echo $USAGE exit 5 fi } case $1 in 1) if [ `date +%d` -lt 8 ] ; then run_prog fi ;; 2) if [ `date +%d` -gt 7 ] && [ `date +%d` -lt 15 ] ; then run_prog fi ;; 3) if [ `date +%d` -gt 14 ] && [ `date +%d` -lt 22 ] ; then run_prog fi ;; 4) if [ `date +%d` -gt 21 ] && [ `date +%d` -lt 29 ] ; then run_prog fi ;; 5) if [ `date +%d` -gt 28 ] ; then run_prog fi ;; -h | --help | -help) cat | less << 'EOD' DAY_OF_MONTH(1) User Manuals DAY_OF_MONTH(1) NAME day_of_month - check, if an date is the N day of the month and run a as parameter given program. Where day is one of Monday to Sunday. SYNOPSIS day_of_month [ --help | 1 | 2 | 3 | 4 | 5 ] PROGRAM DESCRIPTION day_of_month is mainly for the use in crontab files. It allows an easy way to check, if the day you run your cron job is the N day of the month. If it is the given day, it starts PROGRAM. PROGRAM is any executable file. If you will give parameters to your program, your invoking must be quoted. EXAMPLES run a program at 16:05 on each second Saturday of a month, your crontab may look like: 16 05 * * 6 day_of_month 2 "program parameter1 parameter2 ... " OPTIONS -h print this help AUTHOR Wulf Coulmann <scripts at gpl.coulmann dot de> SEE ALSO crontab(1) Linux Last change: August 2006 EOD exit 0 ;; *) echo $USAGE exit 5 ;; esac