一种使用针对 Cisco 的 PuTTY 批处理在 cmd.txt 文件中键入多个命令的方法
A way of typing multiple commands in cmd.txt file using PuTTY batch against Cisco
我在 Windows 环境中使用下面的 PuTTY.exe 命令 运行ning 批处理文件:
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%
)
该批次应加载 PuTTY 中预定义的变量配置文件(n
从 1 到 5),并 运行 在它们上逐一加载 cmds.txt
文件中定义的命令;然后将输出保存到某个文件夹..
然而,在cmds.txt
文件中我只能输入一个命令!
如何在这个 txt 文件上输入多个命令,它应该一个一个地传递给会话,然后将整个输出结果保存到输出文件中?
我尝试按照以下格式在 cmds.txt
文件中输入命令,但不起作用:
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)
预期的结果是在cmds.txt
文件中输入两条或多条命令,应该一条一条传递给会话,然后将整个输出结果保存到输出文件中。
这实际上是 Cisco 的一个已知限制,它不支持 SSH "exec" 通道命令中的多个命令。
引用 PuTTY/Plink 手册的 3.8.3.6 -m
: read a remote command or script from a file 部分:
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.
使用带有输入重定向的 Plink (PuTTY command-line connection tool) 可能会解决问题(无论如何你都不应该使用 PuTTY 来自动执行命令)。
plink.exe -ssh IPAddress -l User -pw Password -load Site%%n% < cmds.txt
我在 Windows 环境中使用下面的 PuTTY.exe 命令 运行ning 批处理文件:
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%
)
该批次应加载 PuTTY 中预定义的变量配置文件(n
从 1 到 5),并 运行 在它们上逐一加载 cmds.txt
文件中定义的命令;然后将输出保存到某个文件夹..
然而,在cmds.txt
文件中我只能输入一个命令!
如何在这个 txt 文件上输入多个命令,它应该一个一个地传递给会话,然后将整个输出结果保存到输出文件中?
我尝试按照以下格式在 cmds.txt
文件中输入命令,但不起作用:
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)
预期的结果是在cmds.txt
文件中输入两条或多条命令,应该一条一条传递给会话,然后将整个输出结果保存到输出文件中。
这实际上是 Cisco 的一个已知限制,它不支持 SSH "exec" 通道命令中的多个命令。
引用 PuTTY/Plink 手册的 3.8.3.6 -m
: read a remote command or script from a file 部分:
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.
使用带有输入重定向的 Plink (PuTTY command-line connection tool) 可能会解决问题(无论如何你都不应该使用 PuTTY 来自动执行命令)。
plink.exe -ssh IPAddress -l User -pw Password -load Site%%n% < cmds.txt