Question

I'm writing a simple deployment script for our code in bash. Currently I have some code like the following, which works fine normally. If for some reason the authentication fails (like the password gets changed but not changed in this script) then the svn command will ask for a password. As this is run through an automated system it will never be seen by someone.

How can I either make svn return a non-0 error code on authentication failure rather than just waiting forever (or as long as I've left it so far) for input?

The code snippet is:

if eval "svn update --username xxxxxxx --password xxxxxxx"; then
    echo "Updated from SVN ok"
else
    echo "Update from SVN failed"
    exit 1
fi

# Do more stuff here as update was ok

Obviously real username/password has been replaced with xxxxx.

If the password is wrong then this is what is output by the svn command:

Updating '.':
Authentication realm: <https://xxxxxxxxxxx:443> SVN
Username:

I appreciate your help.

Was it helpful?

Solution

I think the --non-interactive option may be what you're looking for.

From the output of svn help update:

Global options:
  <skipped a few items here>
  --non-interactive       : do no interactive prompting

I'm not 100% sure, but it sounds like with this option, if a password authentication is required, svn will just fail with a non-zero exit code.

OTHER TIPS

I think the eval is unnecessary (and usually discouraged for security reasons).

I don't know svn well, but its worth trying the --quiet or --force options to see if it will prevent re-asking for username/password:

if svn update --force --username xxxxxxx --password xxxxxxx; then

or

if svn update --quiet --username xxxxxxx --password xxxxxxx; then

Failing that, if you have a recent version of GNU coreutils (I'm assuming your on ), then you can use the timeout command:

timeout 5 svn update --username xxxxxxx --password xxxxxxx
if (( $? != 124 )); then
    echo "Updated from SVN ok"
else
    echo "Update from SVN timed out after 5 seconds"
    exit 1
fi

For tools which lack a command line option, you can redirect standard input, so they don't actually try to read from a (blocking) console:

svn </dev/null update --username xxxxxxx --password xxxxxxx
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top