Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I created cron job to run every two weeks on Monday however it's not working for some reason (the command itself works fine - it's just not executed by ...
  1. #1
    HTF
    HTF is offline
    Just Joined!
    Join Date
    Feb 2011
    Posts
    14

    Cron Job every two weeks

    Hi,

    I created cron job to run every two weeks on Monday however it's not working for some reason (the command itself works fine - it's just not executed by cron). Could you please check if the syntax is correct:

    05 01 * * 1/2 root /bash_script.sh

    Regards

  2. #2
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,281
    How about this;

    5 1 * * 1/2 root /bash_script.sh

    You don't need the leading '0'. It should work.
    How/where did you place this command?

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  3. #3
    HTF
    HTF is offline
    Just Joined!
    Join Date
    Feb 2011
    Posts
    14
    Hi

    I can try without this leading 0 however I have another command which is running fine:

    00 01 * * * root /bash_script.sh

    I just created crontab in /etc/cron.d/ directory

  4. #4
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Leading zeroes is irrelevant so specifying ‘05’ or ‘5’ is the same. The crontab entry:

    05 01 * * 1/2 root /bash_script.sh

    The 5th field specifies day-of-week so ‘1/2’ says to run the script on Monday, Wednesday, Friday, and Sunday (1,3,5,7).

    Cron doesn’t have a way to specify every other week. Best you can do is have your script run every week and put code in your script to determine whether the week of the year is odd or even. So to run the script on an even week of the year:

    Code:
    #!/bin/sh
    
    WK=`date +%W`
    ON_WK=`expr $WK % 2`
    
    if [ $ON_WK = 1 ];
       then echo "NOT even week"
            exit 1
       fi
    To have your script run every Monday:

    05 01 * * 1 root /bash_script.sh

  5. #5
    HTF
    HTF is offline
    Just Joined!
    Join Date
    Feb 2011
    Posts
    14
    Thanks for help.
    - could you confirm what fields (like m, h, d) accept '/' switch

  6. #6
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Refer to the crontab file man page:

    Code:
    # man 5 crontab

Posting Permissions

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