I have a problem where the following function
remote.send("show run int vlan 1\\n")
does not work. The code is below. It is able to read the file, create a new file and write and save the file. However the output only contain the switch name, nothing else and sometimes it will show the switch name and a character or 2 of the command. The output is as follows
switch test1
IP address 1.1.1.51
test1_2023-02-23
Successfully log in to test1
test1#s
switch test2
IP address 1.1.1.50
Test2_2023-02-23
Successfully log in to test2
test2#
Just started to learn the language and I am not sure what the problem is. Thanking you in advance.
myfile = open('c:\znet\device-list.txt','r')
count = 0
while True:
count = count + 1
line = myfile.readline()
if not line:break
else:
x = line.strip()
y,z =x.split(",",1)
print ("switch ",y)
print ("IP address ",z)
backupdate = str(date.today())
filename = y + "_" + backupdate
print (filename)
host = z
user = 'cisco'
password = 'cisco'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
client.connect(hostname=host, username=user, password=password)
print ("Successfully log in to", y)
remote = client.invoke_shell()
remote.send("show run int vlan 1\n")
output = remote.recv(1048576)
print (output.decode('ascii'))
with open("{}.txt".format(filename),"w") as f:
print (output.decode('ascii'),file=f)
I am expecting to see the configuration of vlan 1 (show run int vlan 1
) both on the terminal and in the file created.