I use cron to run an 'svn up' nightly on a directory of files that I need to keep up to date locally while others are working on them. This used to work fine, with a simple:

/usr/bin/svn up /path/to/directory

However, ever since I updated to OS X Lion the other day, the command above works fine in the shell (bash) but when it runs from cron I get

Authentication realm: <https://my-server.com:443> my-server.com Subversion Repository Password for 'my.username': Authentication realm: <https://my-server.com:443> my-server.com Subversion Repository Username: svn: OPTIONS of 'https://my-server.com/path/to/directory': authorization failed: Could not authenticate to server: rejected Basic challenge (https://my-server.com)

I desperately tried adding --config-dir to the command, but it had no effect. The auth credentials seem fine, and in any case they work in bash. I know enough to be dangerous, but I'm at the end of my set of tools here.

Can someone point me in the right direction?

  • 1
    Does your password contain special characters?
    – quanta
    Jul 25 '11 at 15:05
  • I have the same problem. It is not due to shell choice, nor due to path. As in the case of the OP, the output from cron indicates that svn is in fact being run, but the authentication is failing. A can see it asking for a password, and getting no (or incorrect) response. This information is cached in my .subversion settings, since if I run the same command from the command line, I am not even asked for a username or PW. I am issuing a svn export <url> <local filenmae> command. If I issue the same command in the crontab for a svn url that is NOT password protected, then the cronjob works fine. Feb 13 '12 at 5:32

svn is looking for your authentication info that is saved in /home/username/.subversion/auth. But as Mike mentioned, the env is not the same under cron and $HOME is probably different. Try setting $HOME before running 'svn up'.

In /etc/crontab:

0 0 * * * username export HOME=/home/username; /usr/bin/svn up /path/to/update

It's likely that this is due to the fact that the same env is not loaded with cron like it is in a standard shell. You can either

  1. source .bashrc or have a script that does that all for you
  2. use the fully qualified application name rather than the simple command you can use because /usr/bin is on the $PATH

In this very related thread, a user posts some obscure syntax that apparently gets ssh-agent to work. This thread is not svn-specific, but appears to be exactly the same issue. https://apple.stackexchange.com/questions/18832/ssh-under-cron-stops-working-in-os-x-10-7-lion


Create a new shell script that content your SVN command. Then put something like this in cron:

/bin/bash /path/to/your/script.sh

This will make sure that your command are work in bash envelopment.

  • 1
    No dice. Same result as before. Jul 25 '11 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.