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 written a small backup script for my vserver and added its execution to my /etc/crontab

25 * * * * root /etc/cron.daily/backup.sh

This is the entry (yeah it is still located in the wrong folder right now :) ) But when I check my log I see that the script is executed a min of 2 times a hour. Which is not a problem but I would like to know why this is happening.

Backup done on Fr 8. Jun 02:59:00 UTC 2012
Backup done on Fr 8. Jun 03:28:20 UTC 2012
Backup done on Fr 8. Jun 03:58:44 UTC 2012
Backup done on Fr 8. Jun 04:39:44 UTC 2012
Backup done on Fr 8. Jun 05:06:43 UTC 2012
Backup done on Fr 8. Jun 05:32:34 UTC 2012
Backup done on Fr 8. Jun 05:59:06 UTC 2012
Backup done on Fr 8. Jun 06:28:58 UTC 2012
Backup done on Fr 8. Jun 06:59:07 UTC 2012
share|improve this question
    
What's in /etc/cron.d /etc/crontab and /etc/cron.hourly ? –  SmallClanger Jun 8 '12 at 7:29
    
in cron.d is only a script for removing old php sessions, for testing I removed my script from /etc/crontab and put it in /etc/cron.hourly but it is not executed –  soupdiver Jun 8 '12 at 8:49
add comment

1 Answer

up vote 4 down vote accepted

Scripts in /etc/cron.daily are automatically run daily, scripts in /etc/cron.hourly hourly. There is no need to put a script into one of the /etc/cron.{hourly|daily|weekly|monthly} AND calling it from /etc/crontab. Putting your script into /etc/cron.hourly and calling it from /etc/crontab would run the script twice.

I suggest you also add a Backup started log message. That way you will see when it gets called any you can eventually correlate that information with what you have configured.

share|improve this answer
    
Ok I tried it you way but when I just put my script into cron.hourly it never gonna executed that's why I added it manually to /etc/crontab –  soupdiver Jun 8 '12 at 8:48
    
For cron.hourly to work, you need a line such as 17 * * * * root cd / && run-parts --report /etc/cron.hourly in /etc/crontab. Do you have that line? –  Oliver Jun 8 '12 at 8:57
    
yep exactly that line –  soupdiver Jun 8 '12 at 9:00
    
And your /etc/cron.hourly/backup.sh is executable? Then it should definitely work. You can also enter cd / && run-parts --report /etc/cron.hourly on the command line to see what happens. Maybe you will get an error message that tells you why the script isn't run. –  Oliver Jun 8 '12 at 9:07
    
yeah it is executable but even if I run the command manually it is not executed. –  soupdiver Jun 8 '12 at 9:11
show 2 more comments

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.