I'm running Ubuntu 10.04 (64-bit) and have the following script in /etc/cron.hourly
cd /home/chris/path/to/directory
git add .
git commit -m "Commit message"
git push origin master
The file is 775 and I can manually run it run the script and see the commits on the server it's pushing to. Here's the output from a manual run:
chris@IronHide:~$ /etc/cron.hourly/auto-commit
[master 8dc5299] Commit message
4 files changed, 8 insertions(+), 6 deletions(-)
rewrite 1h/1m/c.-b.-6.dat (100%)
Counting objects: 17, done.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 4.64 KiB, done.
Total 9 (delta 3), reused 0 (delta 0)
To <repo_path_cencored>.git
6c6d0ad..8dc5299 master -> master
Don't know if it matters, but my /etc/crontab file looks like this:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
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 )
#
What am I doing wrong?
Best Answer
It looks like when you run the script manually, you do it as
chris
. So why are you trying to run it asroot
under cron?/etc/crontab
(and by extension the/etc/cron.*
directories) are for system jobs. To run a job as your user, runcrontab -e
and write a line likeThis runs
~/bin/auto-commit
in the specified directory hourly at one minute past the hour.