I want to connect from one remote server to other using python script.I already tried in shell script and its works well but it will cause future issues.Hence I want to stick up with python.
I have tried all the links given in stackoverflow and github.But it did not work for me.
The code I tried: [1] CODE 1
import sys
import os
import subprocess
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="root -a"
ssh = subprocess.Popen(['ssh', 'root@10.10.10.3', 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
Connection should be successful using python and one should be able to connect and run any command from one remote server to other using this code.