Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

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)
share|improve this answer
    
It should be like this : 30 19 */3 * * root /var/scripts/svn_backup.pl –  Caterpillar Mar 11 '13 at 6:03
    
Yes. Your Perl script will be run at 19h30 every three days. –  quanta Mar 11 '13 at 6:06
1  
Won't this be run on 30st and then on 3rd again? So there will be 4 days in between? –  Dainis Abols Mar 11 '13 at 11:07
    
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 '13 at 13:39
    
@Downvoter: why the downvote? –  quanta Mar 13 '13 at 1:07
show 1 more comment

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.

share|improve this answer
    
If I have to run the script alternate days, it should be 30 19 */1 * * root /var/scripts/svn_backup.pl Am I right? –  Caterpillar Mar 20 '13 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. –  Iain Mar 20 '13 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. –  Caterpillar Apr 2 '13 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. –  Iain Apr 2 '13 at 7:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.