Take the 2-minute tour ×

For reference, I'm running CentOS 5.5 on the server.

I'm working on a distributed project with several other developers, and we're using Git to manage our repositories. Everything's hosted live on Gitorious and working beautifully. However, we need a branch in our repository to stay synchronized with an external Subversion repo - kind of like a "vendor branch" within Git. Reason is: we're building several things based on this existing open source project (WordPress) and want our working copy to inherit any bugfixes they publish in their own repo.

I've got things set up so that we have a separate branch called "wordpress" that can be kept in sync with the live Subversion repo. To do so, it's as simple as:

git checkout wordpress
git svn rebase
git gc
git push origin wordpress

These commands will:

  1. Make sure we're on the WordPress branch
  2. Re-sync the branch with the live Svn repo
  3. Run garbage collection (otherwise the repository progressively gets unmanageably large)
  4. Push the updated branch to our hosted repository on Gitorious

It's easy enough to run these four commands whenever WordPress trunk updates, but that's annoying and a hassle. I'd love to set this up as a cron job, but I can't seem to figure out how!

I've written a script called wordpress.sh and placed it in the /etc/ folder on the server:

cd /var/www/git/wordpress
git checkout wordpress
git svn rebase
git gc
git push origin wordpress

The script runs just fine. I can SSH into my server, log in as root, and type . /etc/wordpress.sh and everything works just fine. But how can I set this up so that cron does things for me?

I've tried manually adding it to crontab (unsuccessfully), using the Webadmin interface in CentOS to add it as an hourly script (unsuccessfully), and now I'm at a loss! My system logs claim that it's firing (log below):

Feb  4 07:00:01 ---- crond[27745]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 07:01:01 ---- crond[27773]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 08:00:01 ---- crond[29095]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 08:01:01 ---- crond[29142]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 09:00:01 ---- crond[29708]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 09:01:01 ---- crond[29718]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 10:00:01 ---- crond[30328]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 10:01:01 ---- crond[30337]: (root) CMD (run-parts /etc/cron.hourly)

But nothing actually happens unless I log in and run the script manually. Ideas?

share|improve this question
I also tried using the command . /etc/wordpress.sh in the cron job, but that didn't do anything differently. –  EAMann Feb 4 '11 at 15:41
For those interested in a longer discussion of how I finally came to the solution (based on @ygram's advice), check out the follow-up post on my blog: eam.me/e1 –  EAMann Feb 15 '11 at 20:41
add comment

2 Answers

up vote 2 down vote accepted

Cron runs with another environment than a login shell so a likely error is that git is not in the path. The easiest is usually to use the full path of every command in a crontab (/usr/bin/git or wherever your git is installed).

Errors in scripts run by cron is usually mailed to the user, so try to look in root's mailbox.

share|improve this answer
It wasn't throwing any errors ... but I needed to change references to git into /usr/bin/git/git to get it to work. I also had to change the cron command from /etc/wordpress.sh to sh /etc/wordpress.sh to get things to work. Thanks for the help! –  EAMann Feb 6 '11 at 22:11
add comment

Do you run your sites as root? Do you manually run the script as root? I hope you don't.

Now look at cron output: it runs your script from root account, and it probably fails to find the repository. Add it to your account's crontab, not root's.

share|improve this answer
When I wrote this, the only account I had for the system was root. Telling me not to run as root is generally a good idea, but it doesn't help me solve the problem at all. –  EAMann Feb 6 '11 at 22:12
add comment

Your Answer


