问题
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:\Users\emrpocadmin\desktop\putty.exe -ssh IPAddress -l User -pw Password -m c:\Users\emrpocadmin\desktop\cmds.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.
回答1:
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
来源:https://stackoverflow.com/questions/57333997/a-way-of-typing-multiple-commands-in-cmd-txt-file-using-putty-batch-against-cisc