LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   cronjob (https://www.linuxquestions.org/questions/linux-general-1/cronjob-807039/)

janihemang 05-10-2010 04:21 PM

cronjob
 
Hi,

Wondering on what am I doing wrong here. Cron setup for execute at 4:30 pm on 2nd monday of each month.

50 16 8-14 * mon /home/user/script.sh

It seems to be ignoring the date range 8-14?

Any ideas or a better way of setting this up?

thanks.

colucix 05-10-2010 04:43 PM

Most likely the reason is (from man 5 crontab)
Quote:

The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (ie, aren't *), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
that is the day fields are addictive, but one does not exclude the other. Your best bet is to modify the script (if possible) by adding a date check at the very beginning. For example, suppose your crontab is simply
Code:

50 16 8-14 * * /home/user/script.sh
then your script should begin with:
Code:

#!/bin/bash
[ $(date +%u) -ne 1 ] && exit

Hope this helps.


All times are GMT -5. The time now is 09:20 AM.