【发布时间】:2017-05-22 21:46:02
【问题描述】:
这是为了工作......所以我会尽可能多地分享,我正在尝试通过 python 脚本在远程机器上安装“环境”,这个“环境”需要传递给它用户名和密码,我尝试了很多东西,似乎没有任何效果......最接近的是这个脚本,但是在它传递用户名后会弹出一个GUI并要求输入密码......我做错了什么?!或者我该怎么做才能让它工作?!...这是处理 pexpect 的脚本的一部分
import os
import pexpect
cmd = 'ssh -X groupName@machineName cd ~/theLocationOfTheInstallation/ && pwd && theFullPathOfTheFileToInstall'
child = pexpect.spawn(cmd)
cmd_show_data = ''
usr = 'userName'
pas = 'myPassword'
while not child.eof() :
index = child.expect(['Please enter your.*','pass.*', pexpect.EOF, pexpect.TIMEOUT])
cmd_show_data += child.before
child.delaybeforesend = 1
if index == 0 :
print 'user name required, "'+usr+'" is passed'
child.sendline(usr)
elif index == 1 :
print 'password required, "'+pas+'" is passed'
child.sendline(pas)
elif index == 2 :
print 'EOF'
elif index == 3 :
print 'TIMEOUT'
cmd_show_data += child.before
cmd_show_data = cmd_show_data.split('\r\n')
for s in cmd_show_data :
print s
这是弹出的 GUI: 如果我手动输入密码(我试图避免),我会得到这样的输出:
user name required, "userName" is passed
TIMEOUT
TIMEOUT (a lot of times out)
user name required, "userName" is passed
TIMEOUT
TIMEOUT (a lot of times out)
password required, "myPassword" is passed
TIMEOUT
TIMEOUT (a lot of times out).... till the installation is complete.
所以.. 有什么想法吗?
【问题讨论】:
-
说实话......我解决这个问题的所有方法都可能是错误的,我愿意听取任何种解决方案。