0

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
Oliver
  • 5,973
  • 24
  • 33
soupdiver
  • 807
  • 2
  • 9
  • 26
  • What's in `/etc/cron.d` `/etc/crontab` and `/etc/cron.hourly` ? – SmallClanger Jun 08 '12 at 07: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 08 '12 at 08:49

1 Answers1

4

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.

Oliver
  • 5,973
  • 24
  • 33
  • 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 08 '12 at 08: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 08 '12 at 08:57
  • yep exactly that line – soupdiver Jun 08 '12 at 09: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 08 '12 at 09:07
  • yeah it is executable but even if I run the command manually it is not executed. – soupdiver Jun 08 '12 at 09:11
  • Try to add `--verbose` to `run-parts`. See `man run-parts`... – Oliver Jun 08 '12 at 09:13
  • Ok the problem was that my script filename contained a . This is not allowed by run-parts – soupdiver Jun 08 '12 at 09:52