2010年6月18日 星期五

cron with date tip

If need to run a job on the 3rd Wednesday of every month, but cron won’t let me do this. Run every day in the 3rd week, but then check that the day is a Wednesday. e.g.

00 02 15-21 * * if [ `date +\%u` -eq 3 ] ; then run_myjob; fi

Note that the \ is used to escape the %, otherwise cron treats it as a newline.

沒有留言:

張貼留言