cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

26426
Views
0
Helpful
32
Replies
Beginner

Re: ssh (plink) to PIX/IOS with multiple command file works on P

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   privilege 15 secret 0
no username cisco

Replace and with the username and password you want
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

Beginner

Re: ssh (plink) to PIX/IOS with multiple command file works on P

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

Beginner

Re: ssh (plink) to PIX/IOS with multiple command file works on P

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

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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 "term len 0"

     plink -ssh admin@x.x.x.x -pw "sh run" > config.txt

Highlighted
Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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.

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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?

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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.

Beginner

ssh (plink) to PIX/IOS with multiple command file works on PIX b

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. 

Beginner

I've come to a solution, but

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.

 

try using ' < ' insted of -m

try using ' < ' insted of -m parameter The final command will look like this plink -ssh device_ip -l user_something -pw password_something < commands.txt > output.txt

For those still or newly

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.

 

 

Beginner

Hi All,

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)

Beginner

Thank you for sharing this; I

Thank you for sharing this; I was just looking into this problem last week.  I was successful in getting this to work on my switches (Catalyst 3750 running IOS 12.2), but not on my routers (C2911 running IOS 15.1).  By adjusting the line feed spacing between commands, I was able to get it to randomly work on a router (4 times out of about 100, but not repeatable).  I tried your Plink command syntax and line feed spacing, no luck.  It appears to be a timing issue.

There are other solutions, but we're constrained to not loading new software on the workstations, and they have PuTTY / Plink.  Has anyone got this working on a Cisco router running IOS 15.x?

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards