Ubuntu, SVN as root in cronUbuntu, SVN as root in cron

February 24, 2012
Tags: ,

My latest adventure with Linux was today.
I needed to make a cron job to update some folders from SVN periodically. The folders were located in /var/www, so I had to checkout them from SVN using sudo:

sudo co svn://my-svn-repo/my-folder/ ./

When I checked out, my username and password were required, and I answered with yes when asked if I wanted to save these credentials.
When i tried to add the update jobs in crontab, like this:

# sudo crontab -e

and add the line

0 5 * * * /usr/bin/svn up /var/www/next4.me/server/ 2>&1

all I obtained was this in my syslog file:

(CRON) error (grandchild #xxxxx failed with exit status 1)

I managed to find out that this happened because the credentials of SVN were saved not in the root’s home folder, but in my home folder.
All I had to do was to run

sudo -H svn up /path-to-folder/

and to enter again my credentials and to save them. This is because sudo -H uses the root’s home folder as the context for the command, whereas without the -H switch svn uses the current’s user home folder!

I didn’t know that!

The OS is Ubuntu 11.10 Server x64

Be Sociable, Share!

Leave a Reply