运行 SSH 命令

在与 SSH 服务器建立的连接上运行 SSH 外部链接 命令。

命令可用性: 本地 IBM RPA SaaS 和 IBM RPA

脚本语法

IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。

executeSSH --client(SSHSession) --command(String) [--timeout(TimeSpan)] (String)=value

输入参数

下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。

设计器方式标签 脚本方式名称 必需的 接受的变量类型 描述
SSH 连接 client Required SSH Session 包含已建立 SSH 连接的数据的 SSH Session 变量。

您可以使用 SSH 登录 (startSSH) 命令来建立此连接。
命令 command Required Text 要运行的 SSH 命令。
Timeout timeout Optional Time Span, Number, Text 等待该命令运行的最长时间。

输出参数

设计器方式标签 脚本方式名称 接受的变量类型 描述
结果 value Text 返回发送的 SSH 命令的结果。

示例

下面的代码示例演示了如何在 SSH 服务器中运行 SSH 命令。 运行 SSH 命令 (executeSSH) 命令在先前由 SSH 登录 (startSSH) 命令建立的连接内运行 cd home/documents && ls 指令。

defVar --name sshConnection --type SSHSession
defVar --name sshTunnel --type SSHForwardedPort
defVar --name result --type String
// Initiates the connection with an SSH server and tunneling with the destination server.
startSSH --host "172.16.4.200" --username "User Name" --password password --port 22 --keygen "<PRIVATE_KEY_FOLDER>" --passphrase "Key Phrase" --timeout "00:00:05" sshConnection=value
openSSHTunnel --client ${sshConnection} --port 80 --boundport 8090 --destination "Local" --host "192.168.0.10" sshTunnel=value
// Runs the command "cd home/documents && ls" on the SSH server to go to the Documents folder and obtains a list of the filenames in the current directory.
executeSSH --client ${sshConnection} --command "cd home/documents && ls" --timeout "00:00:05" result=value
// Terminates the SSH connection.
closeSSH --client ${sshConnection}
// The SSH server receives commands sent to it. The host, ports and connections used here are only sample data. You need to modify these values to use in your own SSH connection.

限制

运行 SSH 命令 (executeSSH) 命令是无状态的。 每次运行此命令时,每个事务都从头开始。
您可以通过使用 && 分割每个 SSH 命令,从而在一行上传递这些命令。 例如:

cd home/<FILE_PATH> && ls