I am using subprocess to connect ssh session to remote host to execute multiple commands.
My current code:
import subprocess
import sys
HOST="admin@10.193.180.133"
# Ports are handled in ~/.ssh/config since we use OpenSSH
COMMAND1="network port show"
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND1],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
resp=''.join(result)
print(resp)
COMMAND2="network interface show"
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND2],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
resp=''.join(result)
print(resp)
In above case my code asking me to enter password twice.
But what i want make is the password should be ask one time and multiple commands has to be execute.
Please help