I'm having problems saving the output of a script that applies configs to multiple devices and lets me know if a connection to a device has timed out. The script successful logs into the devices, runs the commands, and displays the output. It saves the timed out devices to .txt file, however if multiple devices experience timeouts, it deletes the line with the timed out device and only displays the name of the last device that timed out. Could someone please show me what I should add to my code, so that the names of the all the devices that the script can't connect to?
Timeouts=open("Connection time out.txt", "a")
try:
net_connect = ConnectHandler(**ios_device)
except (AuthenticationException):
print ('Authentication Failure: ' + ip_address_of_device)
continue
except (NetMikoTimeoutException):
print ('Timeout to device: ' + ip_address_of_device)
Timeouts.write(ip_address_of_device)
continue
except (EOFError):
print ('End of file whilte attempting device: ' + ip_address_of_device)
continue
except (SSHException):
print ('SSH might not be enabled: ' + ip_address_of_device)
continue
except Exception as unknown_error:
print (str(unknown_error))
continue
#with open ("Connection time out.txt") as f:
#for line in f:
#print (line),
output=net_connect.send_config_set(commands_list)
print(output)