Find the answer to your Linux question:
Results 1 to 5 of 5
I have a job that needs to run on Tuesdays betweeen the 13th and the 19th and I scheduled it as: 0 9 13-19 * 2 /command_name however today tuesday ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    2

    Lightbulb Cron job to run on Tuesdays between the 13th and the 19th each month


    I have a job that needs to run on Tuesdays betweeen the 13th and the 19th and I scheduled it as:

    0 9 13-19 * 2 /command_name

    however today tuesday 23th, it ran.

    any ideas why?

    Thanks
    Fernando

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    Hi and welcome.

    It ran because today is tuesday.
    The day-of-the-month and day-of-the-week are not an "AND" but an "OR".

    Afaik, vixie cron is not able to to what you want.
    Maybe there is a newer cron daemon with that capability, but I havent found that in a quick google search.
    Last edited by Irithori; 10-23-2012 at 05:42 PM. Reason: mixed up logic operator
    You must always face the curtain with a bow.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    One approximation would be to use the "W" modifier in the day-of-month column.
    W = workday

    This would run the command on the workday closest to the 15th at 9:00.
    Code:
    0 9 15W * * /command_name
    You must always face the curtain with a bow.

  4. #4
    Just Joined!
    Join Date
    Oct 2012
    Posts
    2

    thank you.

    then I will schedule to run every tuesday and will change the shell to verify if the day is between the 13 and the 19

    NUMDAY=`date +%e`
    if [ $NUMDAY -ge 13 ] && [ $NUMDAY -le 19 ];
    then
    ... run command
    else
    ... do not run
    fi

  5. #5
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,221
    Just for reference, fcron can be configured to use AND or OR in regard to the two day columns.
    fcrontab
    If a day of month and a day of week are given, the command will execute only when both match with the current time and date unless option dayor is set.
    Which would keep the schedule logic out of your script.
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •