使用 PuTTY 自动执行命令/脚本 [英] Automating command/script execution using PuTTY

查看:528
本文介绍了使用 PuTTY 自动执行命令/脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些是我需要做的事情:

These are the things I need to do:

  1. 打开putty.exe
  2. 输入用户名和密码.
  3. 运行 shell 脚本.

我正在使用 UFT(VB 脚本).我可以打开 PuTTY,但无法使用 UFT 输入用户名和密码或运行任何命令.

I am using UFT (VB Scripting). I am able to open PuTTY but not able to enter username and password or run any commands using UFT.

还有其他方法可以实现吗?我搜索了一下,发现我们可以使用Plink.那么问题将是整个团队必须为此安装 Plink.这是不可能的.

Is there any other way I can achieve this? I have searched it and found that we can use Plink. Then the problem would be that the whole team will have to install Plink for that purpose. And that is not possible.

提前致谢.

推荐答案

PuTTY 具有 -m 开关,您可以使用它来提供文件的路径,其中包含要执行的命令列表:

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

在您的情况下,commands.txt 将包含您的 shell 脚本的路径,例如:

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

/home/user/myscript.sh

<小时>

虽然为了自动化,您最好使用 Plink 命令行连接工具,而不是您已经发现的 GUI PuTTY 应用程序.Plink 是 PuTTY 包的一部分,所以每个拥有 PuTTY 的人也应该拥有 Plink.


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.

Plink (plink.exe) 具有与 PuTTY 相同的命令行参数.除此之外,您还可以直接在其命令上指定您的命令,例如:

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

或使用其标准输入

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

(当然,您将使用您的语言的重定向机制,而不是 <).

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

请注意,使用 -m 开关或直接在命令行上提供命令意味着非交互模式,而使用标准输入默认使用交互模式.所以结果或行为可能会有所不同.使用 -t-T 切换,分别强制交互和非交互模式.

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.

这篇关于使用 PuTTY 自动执行命令/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆