Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

ssh - A way of typing multiple commands in cmd.txt file using PuTTY batch against Cisco

I am running batch file in Windows environment using PuTTY.exe command below:

for /L %%n in (1,1,5) do (
SET z=Site%%n%
start c:Usersemrpocadmindesktopputty.exe -ssh IPAddress -l User -pw Password -m c:Usersemrpocadmindesktopcmds.txt -load Site%%n% 
)

This batch should load variable profiles (n from 1 to 5) predefined in PuTTY and run on them one-by-one the commands defined in cmds.txt file; then save the output to certain folder..

However, in cmds.txt file i could only enter one command!

How can I enter multiple commands on this txt file and it should be passed to the session one by one and then save the whole output results into the output file?

I tried to enter the commands on cmds.txt file as of below formats but does not work:

show run                 (work as one command only)
show run; show version   (does not work)
"show run; show version" (does not work)
echo show run
echo show version        (does not work)

The expected result is to enter two or more commands in cmds.txt file and it should be passed to the session one by one and then save the whole output results into the output file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 (PuTTY command-line connection tool) with an input redirection may solve the problem (you should not use PuTTY to automate command execution anyway).

plink.exe -ssh IPAddress -l User -pw Password -load Site%%n% < cmds.txt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...