groovy - 如何从soapui groovy脚本执行shell脚本?

标签 groovy ssh soapui

我有保留在远程服务器(Linux计算机)上的shell脚本,并且试图在Windows的SOAPui的各种测试用例执行之间调用该shell脚本。
所以我准备了一个普通的脚本:

def command="/usr/bin/ssh -p password username@IP_address bash -s < /home/test.sh"
def proc=command.execute().text
proc.waitFor()

但不幸的是,我收到一个错误:

java.io.IOException:无法运行程序“/ usr / bin / ssh”:CreateProcess错误= 2,系统在以下行找不到文件指定的错误:6

我试图对此进行更多搜索,但无法获得解决方案。一些链接是:

How to execute shell script using soapUI

http://groovy-lang.org/groovy-dev-kit.html#process-management

最佳答案

如果您发表评论,则表示已在Windows上安装了putty.exe,则可以尝试以下操作。

首先,在Windows本地中创建一个带有远程执行命令的文件,例如,我创建以下C:/temp/commandsToRunRemotely.txt,然后在该文件中放入要执行的命令。作为示例,我使用以下命令:

echo "test remote execution" > /tmp/myfile.txt

然后从SOAPUI中的常规脚本调用putty.exe传递包含要远程执行的命令的本地文件:
def command = "C:/path/to/putty.exe -ssh user@IP -pw pass-m C:/temp/commandsToRunRemotely.text"
def proc = command.execute()
proc.waitFor()

请注意,如果您的Windows路径中包含putty.exe,则只需使用putty.exe而不是完整路径即可。

这只是一个ilustation示例,但是如果要远程执行Shell脚本而不是在命令文件中执行echo "test remote execution" > /tmp/myfile.txt,请直接使用脚本的路径:/home/test.sh
我从此nice answer获得Putty命令行选项

希望能帮助到你,

关于groovy - 如何从soapui groovy脚本执行shell脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36768511/

相关文章:

elasticsearch - 我可以在ES的一个查询中同时运行内联脚本和存储的脚本吗?

Groovy 节点与节点列表

linux - git push origin master 请求远程服务器密码

SSL 客户端 (soapUI) 未使用证书响应服务器 CertificateRequest

java - WLI 转换 xQuery 空节点

logging - 渐变颜色输出

xml - Groovy Node.depthFirst() 返回节点和字符串列表?

soapui - 我在哪里可以看到soapUI 添加到我的请求中的安全 header

c# - SSH.NET 中的 MySQL 端口转发 - 尝试以访问权限禁止的方式访问套接字

Git - 服务器上的 ssh-key