12-03-2009 06:05 PM
I cannot run multiple commands on IOS from SSH batch file -it thinks my file is one command only,
however the same file works on the PIX; do they behave differently or am I missing something ?
eg: commands.ssh (DOS encoded) for PIX:
enable
something
show ntp associations
show ntp status
logout
plink -ssh -batch -m commands.ssh somebody@firewall.whatever.com -pw something
... works fine, but:
eg: commands.ssh (DOS encoded) for IOS:
show ntp associations
show ntp status
logout
plink -ssh -batch -m commands.ssh somebody@router.whatever.com -pw something
line has invalid autocommand "show ntp associations
show ntp status
logout
"
the latter works fine on IOS when only one command specified
same when I try different encodings; eg: UniCode, UTF-8
both users priv15
04-20-2011 04:08 AM
Hi James,
Did you ever get this to work with authentication on the router?
Say you have a brand new router you must access to enter some commands on... The new router will typically prompt you like this:
-----------------------------------------------------------------------
Cisco Configuration Professional (Cisco CP) is installed on this device.
This feature requires the one-time use of the username "cisco" with the
password "cisco". These default credentials have a privilege level of 15.
YOU MUST USE CISCO CP or the CISCO IOS CLI TO CHANGE THESE
PUBLICLY-KNOWN CREDENTIALS
Here are the Cisco IOS commands.
username
no username cisco
Replace
to use.
IF YOU DO NOT CHANGE THE PUBLICLY-KNOWN CREDENTIALS, YOU WILL
NOT BE ABLE TO LOG INTO THE DEVICE AGAIN AFTER YOU HAVE LOGGED OFF.
For more information about Cisco CP please follow the instructions in the
QUICK START GUIDE for your router or go to http://www.cisco.com/go/ciscocp
-----------------------------------------------------------------------
User Access Verification
Username:
I can't get plink to access this router. I've tried using the cisco:cisco@router-ip with plink and i've tried supplying the commands via the configuration text file. Neither works for me.
Any suggestions?
This will be used for zero-touch bulk deployment of routers - all that must be done is connecting a console cable to an access server (reverse telnet) and maybe a lan cable for uploading a new IOS.
Thanks,
/JZN
04-20-2011 04:09 AM
Another feature that would be nice to have is sending BREAK to the router. But I don't see how this is possible using plink
04-20-2011 05:08 AM
Perl seems to be the way to do this. Perhaps using this:
http://nettelnetcisco.sourceforge.net/docs.html
On my way to re-write my script and do more testing....
/JZN
09-23-2011 09:13 AM
for those that are stumbling across this down the road trying to get plink w/ IOS commands to work - like me.
I just wrote a batch script where the individual commands are sent. it's a bit more work but it at least makes plink workable for multiple line commands in IOS. (we're using this to automate config backups so it'll work well for us.)
plinkbatch.bat
plink -ssh admin@x.x.x.x -pw
plink -ssh admin@x.x.x.x -pw
11-04-2013 03:20 PM
Replying to this old thread because I found a solution for Cisco IOS. Although ASA/PIX will accept a multiple-commands file with MS-DOS formatted text, Cisco IOS seems to require a Unix-formatted text file with only line feed (LF's) for your return/end of line character. This syntax now works for me:
plink.exe user@x.x.x.x -pw [snip] < commands.txt >> output.log
11-20-2013 03:08 PM
Mark
Could you share an example of how the commands.txt would look for using the following
terminal length 0
show run
show mac address-table
11-20-2013 03:15 PM
Hi cer42tcent,
The text file would look exactly like your example, but you need to save it in UNIX format. If you are using Windows, you could use a text editor such as Notepad++ or UltraEdit to do this. You will not be able to do this with notepad.exe or MS Word, for example. The reason is that MS-DOS formatted text files use both a carriage-return (CR) and a line feed (LR) for the return/end of line characters.
11-21-2013 03:17 PM
Mark
I have the Notepad++ now but noticed on a XP system the text file in UNIX format looks like
terminal length 0[]show run[]show vtp status[]show ntp status
However, on a Windows 7 system the text file in UNIX format looks like
terminal length0show run show vtp statusshow ntp status
If I run the batch file calling the text file it logons okay but the output to a text file only shows
lab-sw#te
Not sure if its Windows 7 and how the text file saved or what. Unfortunately, I can't connect the XP system to the network.
Did you experience these issues? Any ideas?
11-21-2013 05:34 PM
cer43tcent,
If I look at the UNIX text file in notepad on Win7, it looks like this:
terminal length 0show runshow vtp statusshow ntp statusexit
I did some additional testing with some routers on IOS 12.2/12.4/15.1, and I noticed that I had to specify the SSH version correctly for this to work:
SSH1:
plink.exe -1 user@x.x.x.x -pw [snip] < commands.txt >> output.log
SSH2:
plink.exe -2 user@x.x.x.x -pw [snip] < commands.txt >> output.log
Trying adding a -1 or -2 for your SSH version.
12-03-2013 03:18 PM
Mark,
Thanks for all your suggestions. But I couldn't get the plink to work how you mentioned on switches with IOS 15.0. I ended up having to use Notepad++ and create three seperate text files (3 authentications) to accomplish all the commands I truly wanted.
I figured I'd share to maybe help others trying to accomplish similar. So..the commands I wanted to use were (term len 0, sh int status, sh switch detail, sh arp, sh version, sh ntp status, sh vtp status, show mac address-tab, sh run, and sh span vlan 1-999) In my case first I had to have plink.exe and Putty.exe in the same folder. Then I had to set my default Putty window to a large number for both rows and columns. Next, I created the Unix format text files in Notepad ++. Now to why I had three text files...
For some odd reason I could only run term len 0, show interface status, show switch detail, show arp, show ver, show ntp status, show vtp status, and show mac address on my first text file and the output be correct. The second text file would only do show run and be correct. My third text file only did show span vlan 1-999. The catch seemed to be matching the end of line in Notepad ++ to what the output would be on the Putty terminal before and after each command. However, this didn't work with commands that needed paging (ie show run, show span vlan 1-999) . I attached a screenshot of my first text file in Notepad ++ if anyone cares to see.
Lastly, I'd also like to note that i don't think terminal length 0 actually does it function when using plink.
07-18-2014 11:16 AM
I've come to a solution, but it isn't with plink. Its using Putty through a batch file. The batch file is setup to run Putty and then capture multiple show commands without cutting off some of the output or ending like plink did.
The lines of the batch file look like:
@echo
putty.exe -load LANSW1 -pw P@$$word
Notice the LANSW1. This is a saved session I created in Putty. Now the settings in that saved session I modified were
Logging (where I want the file saved)
Window (increased lines of scrollback to a very high number)
Data (put my account in the Auto-login username field)
So when I run the batch file it starts the saved session and all I have to do is right-click inside the Putty window to paste the show commands I wanted to capture.
Multiple saved sessions can be put in the batch file on a line of their own. When run with multiple sessions, each session starts when the current one is closed.
This helped me save major time, whereas before I'd capture the config and other show output of 26 switch stacks with no application to use (took about 30 minutes or more). Now it took 3 minutes! Not completely automatic, but hopefully this will help someone.
10-04-2022 11:36 PM
Works
Like
A
Charm
THANK YOU SO MUCH !!!
05-23-2014 05:05 AM
06-29-2015 06:29 AM
For those still or newly looking, I found that adding the -1 switch and use the '<' syntax.
plink usera@192.168.1.1 -pw password -1 <"commands.csv" >>ConfigLog.csv
Tested from Win7 PC on both a CISCO1801/K9 & CISCO851W-G-A-K9, noting the CISCO851W-G-A-K9 works with and without the -2.
02-18-2016 03:56 AM
Hi All,
Just in case if someone still having trouble with this, I share what I got working on mine.
Win 7, works with plink fine.
As it was mentioned by other people I used the notepad++ to convert to unix type the end line feeds.
This is the commands file looks like:
###
term len 0
#show version
#show ip interface brief
configure terminal
interface gigabitEthernet2
descri Laz_mod3
ip address 192.168.30.100 255.255.255.0
no sh
exit
exit
exit
####
Every line has the LF on it instead of the DOS type.
Also the link how I send the commands:
plink -ssh -2 -l USERNAME -pw PASSWORD < commands.txt >> putty.log USERNAME@192.168.50.221
Also I attached how looks like the commands txt file when the all view switched on.
I hope it helps you guys.
I needed this to implement sla on our front end routers. (still working on it)
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