1

I am trying to run a set of show commands on a Cisco switch using PuTTY on Windows.

I am not able to use anything other than putty.exe (no Plink, expect, anything!).

I am running the following command in an elevated PowerShell window:

c:\temp\switches\putty.exe -load "cisco" -ssh IPADDRES -l username -pw password -m C:\temp\ciscoCMDs.txt

*The "Cisco" configuration just sets it so it logs the console window to a text file.

The contents of the ciscoCMDs.txt are as follows:

show version
show vlan

When I run the command in an elevated PowerShell window PuTTY launches and says:

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log IPADDRESS 11:58:44 =~=~=~=~=~=~=~=~=~=~=~= Using username "Username".
Line has invalid autocommand "show version show vlan"

If I place a ! at the end of first line...

show version !
show vlan

It runs the show version command, but does not run the show vlan command.

How can I get the second command to run? (I intend on placing several more commands there, but if the second command can run there should be no reason the third... nth... wont run.)

Is there a configuration in the PuTTY profile I need to set up for End of File or End of Line?

Is there a special character I need to add at the end of the line to make it so it knows a second command is coming?

Just to be crystal clear:

  1. I am only able to use PuTTY and SSH to access a Cisco switch.
  2. I can not use any other files or programs other than putty.exe, the SSH connection, and the commands.txt files housing a list of commands.
  3. I would like to run multiple show commands from one .txt file and have the output of the commands logged using a single PuTTY profile and a single command run via PowerShell.
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
JohnKubik
  • 69
  • 1
  • 1
  • 12

1 Answers1

0

It's actually a known limitation of Cisco, that it does not support multiple commands in an SSH "exec" channel command.

Quoting section 3.8.3.6 -m: read a remote command or script from a file of PuTTY/Plink manual:

With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.


Using Plink with an input redirection may solve the problem.


If you are really stuck with PuTTY, then as a really gross hack, you can send key strokes with your PowerShell script to the putty.exe subprocess.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992