4

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?

5
  • What is the relevant from the cron logs. They are probably mixed in with other stuff in /var/log/syslog.
    – Scott Pack
    Sep 16, 2010 at 20:25
  • 1
    Like most cron/scheduled task problems the thing you probably need to look at are related to the environment, and permissions. Check to see that PATH is set right, and so on.
    – Zoredache
    Sep 16, 2010 at 21:33
  • I'm getting the following error that I didn't see before now: Sep 16 12:50:54 IronHide cron[5098]: (CRON) DEATH (can't open or create /var/run/crond.pid: Permission denied) That file is showing the following permissions: -rw-r--r-- 1 root root 5 2010-09-16 15:31 crond.pid
    – PHLAK
    Sep 16, 2010 at 22:33
  • Okay... I've figured out that the cron is running on schedule once an hour, but it's not pushing the git repo because it's running as root. What is the proper way to fix this? chmod the file owner to my user?
    – PHLAK
    Sep 16, 2010 at 22:49
  • Weird, somehow I (or someone) down-voted your question for some reason. Please edit it so I can up-vote it and make it right. Sorry!
    – l0c0b0x
    Sep 17, 2010 at 7:39

1 Answer 1

7

It looks like when you run the script manually, you do it as chris. So why are you trying to run it as root under cron? /etc/crontab (and by extension the /etc/cron.* directories) are for system jobs. To run a job as your user, run crontab -e and write a line like

01 * * * * cd ~/path/to/directory && ~/bin/auto-commit

This runs ~/bin/auto-commit in the specified directory hourly at one minute past the hour.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .