I need to receive full output from .recv function in paramiko. I tried to increase the nbyte number, but in my own opinion, I think it's not the proper way to do that. the main purpose of the script to automate list of commands at the same session. my main problem here is that I cant receive the full output from the shell.
Environment:
- python v2.7.14
- paramiko v2.4.1
My Script code: ()
#!/usr/bin/env python
import sys,os,time
import paramiko
user = raw_input("Enter your username please: ")
upassword = getpass.getpass()
ip = "172.x.x.x"
username = "ikxxxx"
password = "xxxgdxx"
ofile = open("ipsadd.csv", "r")
def sshConnection(ip):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=user, password=upassword)
connection = ssh.invoke_shell()
for line in ofile:
hostname = line.split(",")[0].strip()
print "\n\n"
print "Configuration running on: " + hostname
host = line.split(",")[1].strip()
print "IP: " + host
print "*" * 40
connection.send("ssh " + username + "@" + host + "\n")
time.sleep(1)
connection.send("\n")
time.sleep(2)
connection.send("yes" + "\n")
time.sleep(2)
connection.send(password + "\n")
time.sleep(1)
connection.send("screen-length 0 temporary" + "\n")
time.sleep(2)
connection.send("clear alarm al no-trap" + "\n")
time.sleep(2)
connection.send("Y\n")
connection.send("display device\n")
connection.send("display temperature\n")
connection.send("display device pic-status\n")
connection.send("display power\n")
connection.send("display health\n")
connection.send("display cpu-usage\n")
connection.send("display memory-usage\n")
connection.send("display alarm all\n")
connection.send("display switchover state\n")
connection.send("display startup\n")
connection.send("display version\n")
connection.send("display interface brief\n")
connection.send("display isis peer\n")
connection.send("display isis peer verbose\n")
connection.send("display bgp vpnv4 all peer\n")
connection.send("display bgp vpn4 all peer verbose\n")
connection.send("display bgp peer\n")
connection.send("display current-configuration\n")
time.sleep(1)
connection.send("q\n")
output = connection.recv(999999)
print output
break
sshConnection("179.x.x.x")