這是爲了工作......所以我會盡我所能分享,我試圖通過python腳本在遠程機器上安裝「環境」,這個「環境」要求傳遞給它的用戶名和密碼,我嘗試了很多東西,似乎沒有任何工作......最接近的是這個腳本,但它通過用戶名後彈出一個GUI並要求輸入密碼......我是什麼做錯了嗎?! ?!或者我能做些什麼,使工作...這裏是與Pexpect的處理腳本的一部分通過python腳本在遠程機器上安裝軟件
import os
import pexpect
cmd = 'ssh -X [email protected] 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.
so .. any ideas?
說實話......我所有的方法來解決這個問題,可能是錯的,我願意聽到** **任何一種解決方案。 –