05-18-2025 09:55 PM
Good day everyone.
My name is Johannes Robbetze and I am new to the automation side of things. I try to write a Python script that will log in to multiple Cisco switches and change the local username and password as well as the enable secret password. When I run the script I get the below output and it does not change the config. Could I please ask for some help in pointing me in the correct direction to fix the code.
SSHSCRIP.py
05-19-2025 03:43 AM
From your script I'm not sure why is not working. I would assume the commands you have on config_file.txt works, however assuming is not good.
So my advice is:
Another piece of advice is to use context managers (with) rather than opening and closing files, this makes the code easier to read and you will be sure your close your reading.
05-19-2025 03:59 AM
Hi,
It looks like you're just sending the text without a newline/enter.
I haven't worked with paramiko, but other examples I've found included a newline character in the .send command.
So instead of "remote.send('term len 0')" you should probably be doing "remote.send('term len 0\n')"
(Adding the " \n " at the end)
That being said, there are two other observations I would like to point out:
#1
While I'm not that familiar with paramiko, in the past I've been using netmiko, which is very useful for this sort of thing, as it handles some of the basics so you don't need to send individual commands such as the term length and enable.
I've found it easy to use if I'm using python to do any mass-changes.
#2
I'm not sure if the output you posted is from a LAB environment or not, but your password you use can be seen in the screenshot.
If by any chance this is something you use you should now consider the password to be compromised.
05-19-2025 05:30 AM
Hi Jonathan
Thank you. The password that you see is just a test and not the real password that will be used. Let me check with the suggested changes if I can get it to work. Thank you
05-19-2025 10:51 PM
Thank you to everyone who gave some input. I have changed the script and now it is working as expected.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide