batch-file - 如何将参数传递给 PuTTY 命令文件

标签 batch-file cmd scripting putty

我有一个批处理文件,它启动 PuTTY 并执行文本文件中列出的命令。我希望能够将参数传递给文本文件,该文件具有要在远程服务器上运行的命令。

这就是我目前拥有的 -

start C:\Users\putty.exe -load "server" -l userID -pw Password -m commands.txt

有没有办法将例如版本号作为参数传递给 commands.txt文件?

最佳答案

您必须生成 commands.txt即时:

set PARAMETER=parameter
echo ./myscript.sh %PARAMETER% > commands.txt
start C:\Users\putty.exe -load "server" -l userID -pw Password -m commands.txt

旁注:要自动执行任务,您应该考虑使用 plink.exe 而不是 putty.exe :
set PARAMETER=parameter
echo ./myscript.sh %PARAMETER% > commands.txt
plink.exe -load "server" -l userID -pw Password -m commands.txt

Plink 甚至可以在其命令行上接受命令,这使您的任务更加轻松:
plink.exe -load "server" -l userID -pw Password ./myscript.sh parameter

关于batch-file - 如何将参数传递给 PuTTY 命令文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36335882/

相关文章:

c#启动进程参数传入数据

batch-file - 如何通过命令行使用特定配置文件创建 WinRAR、RAR 文件

windows - 使用 Windows 批处理命令追加到文件时,如何在文件中的下一个单词之后立即追加?

linux - 如何在 Linux 上的某个时间运行脚本?

支持 "edit and continue"或 "hot swap"的脚本语言? (也许在 Lua 中可能吗?)

bash - 如何使用 shell 脚本将多个文件从 mp4 转换为 flv

c# - 使用 java 命令将 xml 批处理转换为 C#

python - 在 Windows 的 cmd.exe shell 中,如何将 Perl 脚本的输出通过管道传递给 Python 脚本?

windows - 如何在 FOR/F 循环下获取提示用户输入(set/p)

batch-file - 我需要帮助,当用户输入非法字符时如何停止关闭此批处理文件