I've been trying to create a script that would back up our switches from a CSV file. I'm using Paramiko to SSH into a switch and run "show run", but for some reason the only output I'm receiving is the name of the switch.
import pandas
import paramiko
# Connection info
USERNAME = "username"
PW = "password"
PORT = 22
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Backup \ import location
DEST = "C:\\temp\\test\\"
CSV = DEST+"Switches.csv"
device_list = pandas.read_csv(CSV)
for index, row in device_list.iterrows():
IP = row["IP"]
floor = row["Floor"]
side = row["Side"]
formatted_ip = IP.replace(".", "_")
filename = f"{formatted_ip}_{floor}{side}.txt"
ssh.connect(hostname=IP, username=USERNAME, password=PW, port=PORT)
stdin, stdout, stderr = ssh.exec_command('show running-config')
stdin.close()
output = stdout.readlines()
errors = stderr.read()
print(output)
print(stderr.readlines())
outfile = open(DEST + filename, "w")
for char in output:
outfile.write(char)
ssh.close()
outfile.close()
The output I'm receiving (and also writing into the created file) is SW-3A-48p-4>
I'm able to connect to the switch and run "show run". I'm expecting to get the whole switch configuration but the output stops on the first line.