Hi,
I want to write a python program for connect to remote server (using ssh) and execute the command and return back with output. Here is my code:
import sys
import os
from subprocess import Popen, PIPE, STDOUT
from time import sleep
from os import waitpid, execv, read, write
#Ports are handled in ~/.ssh/config since we use OpenSSH
COMMAND="uname -a"
ssh = subprocess.Popen(['ssh', 'uname@hostname', COMMAND],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
print result
If I execute this code it will ask for password. I want to run the code so that script should not ask password.
pexpect module will support for linus not windows. Could you please help me on this.
If you want more info let me know.
Thanks,
Mahadev