batch-file - 一种在 cmd.txt 文件中使用 PuTTY 批处理对 Cisco 键入多个命令的方法

标签 batch-file ssh command putty cisco

我正在使用下面的 PuTTY.exe 命令在 Windows 环境中运行批处理文件:

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 文件上输入多个命令,并将其一一传递给 session ,然后将整个输出结果保存到输出文件中?

我尝试在 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 中输入两个或更多命令文件,它应该被一一传递给 session ,然后将整个输出结果保存到输出文件中。

最佳答案

这实际上是 Cisco 的一个已知限制,它不支持 SSH“exec” channel 命令中的多个命令。

报价栏3.8.3.6 -m : read a remote command or script from a file PuTTY/Plink 手册:

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

关于batch-file - 一种在 cmd.txt 文件中使用 PuTTY 批处理对 Cisco 键入多个命令的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57333997/

相关文章:

batch-file - 将控制权从外部命令返回到批处理文件

java - YASJW 批处理脚本中的路径行为不一致

git - 在没有 gitosis/gitolite 的情况下通过 SSH 运行 “secure” git 服务器?

python - 带有 Paramiko exit while 循环的嵌套 SSH

linux - Arduino 无法从串口读取

linux - expect Interact 一遍又一遍地读取匹配的行而不继续前进

python - 将用户输入的字符串插入 Linux 命令 [python 脚本]?

c++ - 带命令提示符的命名管道

windows - 是否可以编辑已在 Windows 批处理中输出的行?

linux - 通过本地主机上的 SSH 代理在浏览器中访问应用程序。