简体   繁体   中英

bash script credentials for subversion

Below script works fine when username/password is right on first attempt but when i intentionally give wrong username/password it errors out. But how can i have the script to prompt username and password again if commit fails for wrong credentials ?

#!/usr/bin/bash

read -p "Enter message: " svnmessage
read -p "Enter username: " username
read -s -p "Enter Password: " password


svn commit test.log -m "$svnmessage" --username $username --password $password --non-interactive

When i give wrong username/password:

Enter message: some message
Enter username: wrong name
Enter Password:
svn: E170001: Commit failed (details follow):
svn: E170001: POST of '/svn/IL_IES_Demo/!svn/me': authorization failed: Could not authenticate to server: rejected Basic challenge (http://10.118.19.200:8080)

I'm guessing you can pass --non-interactive to svn to prevent this:

svn commit test.log -m "$svnmessage" --non-interactive --username $username --password $password

I'm assuming svn commit will return 0 on success, so (untested):

#!/usr/bin/bash

while true
do
    read -p "Enter message: " svnmessage
    read -p "Enter username: " username
    read -s -p "Enter Password: " password

    svn commit test.log -m "$svnmessage" --non-interactive --username $username --password $password

    if [ $? -eq 0 ]
    then
        break
    fi
done

Alternatively, you may want to look into using svn+ssh:// authentication. In which case you can setup a SSH public key pair with no password and have your script use that to authenticate with the SVN server. Which is ideal for situations where you are doing non-interactive scripts, but also useful for users who are annoyed by putting in their password all the time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM