this is for work... so i will share as much as i can, I'm trying to install "environment" on a remote machine via python script, this "environment" require to pass to it user name and password, I tried a lot of things, nothing seems to work... the closest thing is this script, yet after it passes the user name a GUI popup and ask for the password... what i'm doing wrong ?! or what can i do to make it work?!... here is a part of the script that deal with 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
this is the GUI that popup :
if i enter the password manually (which i'm trying to avoid), i get output like this :
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?
If you really want to do this job with only Python, why can't you use Ansible instead?
Ansible solution:
If you have a script which installs software locally, then run that script in remote servers with the Ansible script module
Python file example :
Here are some documentation links:
http://docs.ansible.com/ansible/script_module.html
http://docs.ansible.com/ansible/intro_adhoc.html