There is text file called ip_addresses.txt containing 3 IP addresses:
192.x.x.x
192.x.x.x
192.x.x.x
I want to ssh to all of these servers and execute a shell command. Here is code snippet:
ip = open("ip_addresses.txt", "r")
data = ip.readlines()
for ips in data:
ips = ips.strip("\n")
ssh = subProcess.Popen(["ssh", "%s" % ips], stdin = subprocerss.PIPE, stdout= subprocess.PIPE, stderr =subprocess.PIPE)
ssh.stdin.write("ls -ltr")
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" %error
else:
print result
But to ssh make a ssh connection to these servers, I have to provide a username and password too, which are root and sam@123. How can I provide these details as well and check a successful login to the servers.
Thanks