09-20-2018 11:53 AM
I am looking for a way to create a "BATCH" or "BASH" like set of commands where I can log into a new switch, and run a prewritten set of commands.
I would also be VERY open to executing this on an RaspberryPI where I can plug into the USB-B interface and automatically set/do the following:
Any help/advice/documentation/reading material will be greatly appreciated.
Thank you in advance.
09-20-2018 12:46 PM
Coming from the world of Windows I personally use plink to handle things like this. It is just the command line version of Putty but it allows you to pass a file containing commands to be automatically run on the target you are connecting to.
It handles serial connections well and since it is a cmd line tool you can just make a 1 line script so you don't have to manually run the command every time.
Say you have a txt file containing the commands you want to run called commands.txt, just one command per line just like you would manually type it on the switch. You get plink and connect to the switch with a serial connection on COM1
You could then run this command from powershell/cmd
plink.exe -serial COM1 -m commands.txt
It will then connect to the switch on COM1 and run the commands contained in the file. Hopefully this helps, I find it is a quick and easy utility for pushing commands, I am not 100% sure but I believe you can also get plink on linux too, if you wanted to go with your RaspberryPi idea.
09-20-2018 01:30 PM
Genius. I am going to try this now. It's a quick solution to avoid unnecessary typing. In the future, I will attempt something on the RPi.
Thanks again!!
09-20-2018 01:56 PM - edited 09-20-2018 01:57 PM
I just attempted this and it did not work. I have included the BATCH file below.
I used the "echo. |" as a preceding command to create the initial "Enter" command so I can access the command link of the CLI on the switch.
timeout 5 @echo off echo. echo. echo .. READ ME .. echo. echo. echo You will be asked to enter the Port Number you want to connect to echo You can check the device manager to see what port you are connected to. echo Just enter the number, i.e 4, 5, 6, 7, ... etc. echo. echo. echo. echo. set /p PortInput=Enter the JUST the Port number you want to connect to: echo.| plink.exe -serial COM%PortInput% -m 3560_8_PortSwitch.txt ::plink.exe -serial COM%PortInput% -m 3560_8_PortSwitch.txt echo. echo.
The .TXT file is as follows:
enable interface range GigabitEthernet 0/1-8 power inline static no cdp enable exit exit copy running-config startup-config
Any idea why this is not running the text files commands?
09-21-2018 07:07 AM
It has been a while since I used plink for serial connections, I forgot the -m was only for SSH sessions.
You should be able to use < in lace of -m in your script to pass the contents of the file to plink.
echo.| plink.exe -serial COM%PortInput% < 3560_8_PortSwitch.txt
09-21-2018 07:21 AM
I just saw that... using the "<" symbol now leaves me with a Prompt window with a blinking cursor. I can press enter, but this time I won't enter into the switch console. I can issue commands such as "dir", but it yeilds nothing in return.
If I enter "enable" or any other switch related command I get the following error: "'enable' is not recognized as an internal or external command, operable program or batch file."
The code was changed to:
cd %CD%\SwitchConfigs timeout 5 @echo off echo. echo. echo .. READ ME .. echo. echo. echo You will be asked to enter the Port Number you want to connect to echo You can check the device manager to see what port you are connected to. echo Just enter the number, i.e 4, 5, 6, 7, ... etc. echo. echo. echo. echo. set /p PortInput=Enter the JUST the Port number you want to connect to: ::echo.| plink.exe -serial COM%PortInput% -m 3560_8_PortSwitch.txt CMD /k echo.| plink.exe -serial COM%PortInput% < 3560_8_PortSwitch.txt echo. echo.
and text file remains:
enable interface range GigabitEthernet 0/1-8 power inline static no cdp enable exit copy running-config startup-config exit
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