cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
49558
Views
0
Helpful
34
Replies

ssh (plink) to PIX/IOS with multiple command file works on PIX but not on IOS ?

nlariguet
Level 1
Level 1

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

34 Replies 34

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?

No worries, I just checked mine and it's a CSR1000V with 15.5(2) IOS and it runs fine on this.
But the CSR runs on a VMware host. Looks like it depends on the HW and SW as well.

revoice01
Level 1
Level 1

This zombie thread keeps coming back to life but I worked out a solution that works...some of the time?

I hope this help someone else or if anyone finds a way to make it more consistent, please let me know!

#List of devices to connect to
$netdevices = "10.11.10.1", "10.10.10.1"

#temp file with commands
$commandfile = "c:\temp\commands.txt"

#put your commands here
$commands = 'show priv
show vlan
exit'

#export commands to the temp file
$commands | Out-File $commandfile -Encoding ascii

#login information for the devices
$credentials = Get-Credential

ForEach($netdevice in $netdevices){
#Execute the commands on each device
echo Y | cmd.exe /c plink.exe $netdevice -l $($credentials.UserName) -ssh -2 -pw $($credentials.GetNetworkCredential().password) `< $commandfile
}

#clear the temp command file in case anything is sensitive
$null | out-file $commandfile

Not sure if anyone still needs this but I have been using this format on NXOS devices.
It's a little long winded but works for me.
plink.exe -ssh username@FQDN or IP -pw PASSW0RD "sh run ; echo ; sh flogi da ; echo ; sh port-channel summary ; echo ; sh lldp nei" >> "C:\Backups\hostname\""%time:~0,2%%time:~3,2% %date:~0,2%-%date:~3,2%-%date:~6,4%-hostname.txt"

I use this to turn CDP off
plink.exe -ssh username@FQDN or IP -pw PASSW0RD "conf t ; echo ; no cdp enable ; echo ; sh cdp nei ; echo ; sh run" >> "C:\Backups\hostname\""%time:~0,2%%time:~3,2% %date:~0,2%-%date:~3,2%-%date:~6,4%-hostname.txt"

For me what worked was saving the text file as a Macintosh file with (CR) as the end of Line. So a example of my text file is -

 

 

plink -2 -load "putty profile" -l "login_name" -pw "password" < commands.txt -no-antispoof > output.txt

 

command.txt was saved in Macintosh format using notepad++ you can do this by going to Edit -> EOL Conversion -> Macintosh (CR)

 

Hope this helps others.

 

OS: Windows 10

Cisco Device: Cisco ISR 4451-X