[英]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: 我猜测您可以将
--non-interactive
传递给svn
来防止这种情况:
svn commit test.log -m "$svnmessage" --non-interactive --username $username --password $password
I'm assuming svn commit
will return 0
on success, so (untested): 我假设
svn commit
成功时将返回0
,所以(未测试):
#!/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. 另外,您可能希望使用svn + ssh://身份验证。 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.
在这种情况下,您可以设置不带密码的SSH公钥对,并让您的脚本使用它来向SVN服务器进行身份验证。 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.
对于您正在执行非交互式脚本的情况而言,这是理想的选择,但对于一直因输入密码而烦恼的用户而言,它也很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.