I have two lists, the first list is hostnames to ssh to, the second list is a tunnel to look for on the given hostname. I need the first item in list hostnames to run only the first item in list tunnels. Then I need the second item in list hostnames to run only the second item in list tunnels. Below is a sample of what I was using, but clearly isn't working for me.
hostnames = ["router1", "router2"]
tunnels = ["Tu1000", "Tu5000"
for i in range (0, len(hostnames)):
try:
ssh1 = paramiko.SSHClient()
ssh1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh1.connect(hostnames[i], port=22, username=username, password=password, look_for_keys=False, allow_agent=False)
print "SSH connection to %s established.\n" % hostnames[i].upper()
ssh = ssh1.invoke_shell()
for j in range(0, len(tunnels)):
ssh.send("!\n")
ssh.send("en\n")
ssh.send(password)
ssh.send("\n!\n")
time.sleep(1)
output = ssh.recv(65535)
ssh.send("sh int desc | i " + tunnels[j] + "\n")
time.sleep(1)
output = ssh.recv(65535)
output = output.split(" ")
cli_hostname = output[55]