[英]installing software on remote machine via python script
這是為了工作...所以我將盡我所能,我正在嘗試通過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.
所以..有什么想法嗎?
如果您真的只想用Python來完成這項工作,為什么不使用Ansible呢?
Ansible解決方案:
如果您有在本地安裝軟件的腳本,請使用Ansible腳本模塊在遠程服務器中運行該腳本
# Example from Ansible Playbooks
- script: /some/local/script.py 1234
Python文件示例:
#!/usr/bin/python
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print '1st Argument :', str(sys.argv[1])
以下是一些文檔鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.