使用密码输入自动执行“svn up”

2024-05-23 23:24:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一个脚本来更新我的存储库副本。当我输入“svn up”时,我通常被迫输入密码,如何自动输入密码?在

我所做的:

import pexpect, sys, re

pexpect.run("svn cleanup")

child = pexpect.spawn('svn up')
child.logfile = sys.stdout

child.expect("Enter passphrase for key \'/home/rcompton/.ssh/id_rsa\':")

child.sendline("majorSecurityBreach")

matchanything = re.compile('.*', re.DOTALL)

child.expect(matchanything)

child.close()

但它似乎没有更新。在

编辑:如果重要,我可以让我的存储库更新儿童互动()

^{pr2}$

允许我输入密码并开始更新。但是,无论如何,我最终还是犯了一个错误。在

-bash-3.2$ python2.7 exRepUpdate.py 
Enter passphrase for key '/home/rcompton/.ssh/id_rsa':  

At revision 4386.
At revision 4386.
Traceback (most recent call last):
  File "exRepUpdate.py", line 13, in <module>
    child.interact()
  File "build/bdist.linux-x86_64/egg/pexpect.py", line 1497, in interact
  File "build/bdist.linux-x86_64/egg/pexpect.py", line 1525, in __interact_copy
  File "build/bdist.linux-x86_64/egg/pexpect.py", line 1515, in __interact_read
OSError: [Errno 5] Input/output error

编辑:好吧,我找到了一种绕过明文密码输入的方法。我遗漏了一个重要的细节(老实说,我认为我不需要这个,因为这看起来是一个简单的问题),那就是当我第一次获得回购时,我必须向我们的it部门发送一个公钥。在ssh+svn中避免密码输入可以通过ssh代理来完成。这个链接:http://mah.everybody.org/docs/ssh提供了一个简单的概述。Joseph M.Reagle通过Daniel Starin的方式只需要我在登录时输入一次密码,这样我就可以每天晚上执行我的脚本,尽管密码输入了。在


Tags: inpybuildrechild密码linuxline
2条回答

实际上,您应该将ssh与公钥一起使用。在

如果没有,您只需在~/.subversion/auth/svn.simple/中创建一个新文件,其中包含以下内容:

K 8
passtype
V 6
simple
K 999
password
V 7
password_goes_here
K 15
svn:realmstring
V 999
<url> real_identifier
K 8
username
V 999
username_goes_here
END

999个数字是下一行的长度(减\n)。文件名应该是领域字符串的MD5和。在

如果您不想多次输入密码,但仍然有一个安全的解决方案,您可以使用ssh代理来保存您的密钥密码短语一段时间。如果您使用默认私钥,只需键入ssh-add并在询问时提供密码短语。在

有关ssh-add命令用法的详细信息如下:linux.die.net/man/1/ssh-add

相关问题 更多 >