Automating command/script execution using PuTTY

和自甴很熟 提交于 2019-11-28 09:33:50

PuTTY has the -m switch, that you can use to provide a path to a file with a list of commands to execute:

putty.exe user@example.com -m c:\local\path\commands.txt

Where the commands.txt will, in your case, contain a path to your shell script, like:

/home/user/myscript.sh

Though for automation, your better use the Plink command-line connection tool, instead of the GUI PuTTY application, as you have already found out. The Plink is a part of PuTTY package, so everyone who has PuTTY should have Plink too.

The Plink (plink.exe) has the same command-line arguments as PuTTY. And in addition to those, you can specify your command directly on its command like:

plink.exe user@example.com /home/user/myscript.sh

or using its standard input

plink.exe user@example.com < c:\local\path\command.txt

(or course, you will use redirection mechanism of your language, instead of the <).


Note that providing a command using the -m switch or directly on command-line implies a non-interactive mode, while using the standard input uses an interactive mode by default. So the results or behavior may differ. Use the -t and -T switches to force the interactive and the non-interactive mode, respectively.

You can add cmd arguments when you launch putty directly;

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

Can you not request the user name and pass prior and pass this along to the executable?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!