Open joand3512004 opened 1 year ago
Did you work this out?
Why do you try to make a new SSH connection for each command
that you send?
What is the error that you run into?
Hi, Maybe your code is missing reading the files you open. Try adding these parameters:
my_devices = open("device_list.txt") my_device_list=my_devices.read().splitlines() comandos = open("cli.txt") comandos_list=comandos.read().splitlines() devyces = []
for device_ip in my_device_list:
device = {
"device_type": 'cisco_ios',
"ip": device_ip,
"username": username,
"password": passw,
}
devyces.append(device)
for device_ip in devyces: for comand in comandos_list: try:
net_connect = ConnectHandler(**device_ip, session_timeout=100)
print(f'\n Conectando no Switch:{device_ip["ip"]}')
output = net_connect.send_command(comand)
print (f'\n Enviando o comando: *{comand}*\n')
print(output)
print ('== Logout device', device_ip['ip'],' ==')
net_connect.disconnect()
#continue
except NetMikoTimeoutException:
print(f'\n Erro de TimeOut: *{device_ip}*')
pass
except AuthenticationException:
print(f'\n Erro de Credencial: *{device_ip}*')
pass
except SSHException:
print(f'\n Erro de Acesso: *{device_ip}*')
pass
net_connect.disconnect()
regards. Nbz
I had a perfectly working code, but I lost my computer, and I didn't save the backup. Now, I need to back up several switches again, and my code reads 2 files:
1 = cli 2 = device_list
However, for some reason, the script only reads the first switch, and stops running, anyone to help?