Difference between using crontab and /etc/cron.hourly,daily,weekly
I have a scheduled script that does an hourly svnsync backup of our Subversion repositories. I was running it from an entry in the root crontab without problems, but decided I'd like to run it from /etc/cron.hourly instead for extra visibility (and because one of our engineers accidentally deleted the crontab because he thought "crontab -r" meant "read the crontab ;-))
The svnsync commands in the cron.hourly script all fail with a message saying that the SSL certificate for the SVN repository needs to be accepted (this is the message you get interactively the first time that user accesses the SVN repository, but once the certificate I accepted the message doesn't come up again).
So it seems to me that the script is being executed under a different user environment when run from cron.hourly than when it's run via the root crontab. Can anyone explain the difference ?
UPDATE: I should have mentioned my distro, I'm using anacron on CentOS 5.1.
UPDATE 2: Thanks for the suggestions so far; I think this is turning into more of a Subversion question. I always try to encapsulate my environment into my scripts, but the problem here is that I'm not sure what it is in (or lacking in) the environment that makes SVN ask for the SSL certificate to be accepted when I run my script from cron.hourly. I'm guessing it's something to do with the way that the run-parts script is executed.
Solution 1:
You want to use the '--config-dir' option to let it know where to find the accepted cert (e.g. ~/.subversion by default).
That said, I'm almost certain you'd be better off calling svnsync from the hooks/post-commit script instead, as suggested elsewhere. Then your mirror is always in sync, rather than in sync with where your master was an hour ago.
Solution 2:
On Debian/Ubuntu system cron.daily|weekly|montly are started from the main crontab.
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Also keep in mind that you probably could place a crontab fragment in /etc/cron.d/
As you can see there isn't anything particularly special about this environment. At least on Debian/Ubuntu it all is run as the root account.
When I write cron scripts at the very start of the script I always set my PATH and other environment variables i will be using, so I can be certain that it will work correctly in any environment.