7

I have some Perl scripts which needs to be runned every 3 days once, The following is syntax which I have entered, Can you please let me know, Is this correct or wrong.

30 19    * * */3   root   /var/scripts/svn_backup.pl

2 Answers 2

13

It's wrong. The last column is the day of week. You probably want to move */3 to the third column (day of month):

*     *     *     *     *      command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
6
  • It should be like this : 30 19 */3 * * root /var/scripts/svn_backup.pl Mar 11, 2013 at 6:03
  • Yes. Your Perl script will be run at 19h30 every three days.
    – quanta
    Mar 11, 2013 at 6:06
  • 2
    Won't this be run on 30st and then on 3rd again? So there will be 4 days in between?
    – Peon
    Mar 11, 2013 at 11:07
  • 1
    I was going to say yes, but it seems to run on the 28th and again on the 1st as mentioned in the other answer (proof: goo.gl/PSwY4). Your point is valid though, since it would only leave a 3-day gap on months containing 30 days (Apr/Jun/Sep/Nov). All other months would have a 1-day gap except February on a leap year. Choosing two weekdays instead might give more consistent results (eg. Tuesday and Friday: 30 19 * * 2,5).
    – deizel.
    Mar 11, 2013 at 13:39
  • 1
    Because this isn't "every three days" but "every three days and sometimes even more often". (See @lain's answer) Depending on OP's scenario your answer could possibly do some damage. I'm not the downvoter btw, but maybe you should just add a note about that pitfall. Mar 13, 2013 at 9:25
14

The */3 is in the wrong column your specification should be

30 19 */3 * * root /var/scripts/svn_backup.pl 

The */3 syntax is the same as saying 1,4,7 ... 25,28,31. Note that some months it will run on 31st and the next month it will run on the 1st because the interval specifications do not wrap, they always start at the beginning of a sequence. In this case your script gets run without the required interval.

If you need something to run every 3 days then you would have to run your script every day and have it determine if 3 days have passed and exit/continue as appropriate.

In perl you could do something like

if ( int (time/86400)%3 != 0)  {exit 0};

which would run the script every 3 days based on the UNIX epoch.

4
  • If I have to run the script alternate days, it should be 30 19 */1 * * root /var/scripts/svn_backup.pl Am I right? Mar 20, 2013 at 7:11
  • 1
    @Caterpillar:No, */1 is the same as * it will run every day. */2 would be every other day but again it would occasionally run on the last day of one month and the first day of another without a skipped day.
    – user9517
    Mar 20, 2013 at 7:16
  • @lain, Now I am running all the scripts 2days once i.e, The script runned on 31st it instead of running on 2nd of next month, It runned on 1st of this month, I did not understand that. Can you tell me how is it possible. Apr 2, 2013 at 4:39
  • @Caterpillar: I answered this already Note that some months it will run on 31st and the next month it will run on the 1st because the interval specifications do not wrap, they always start at the beginning of a sequence.
    – user9517
    Apr 2, 2013 at 7:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .