【问题标题】:how to execute shell script from soapui groovy script?如何从soapui groovy脚本执行shell脚本?
【发布时间】:2016-08-14 14:10:14
【问题描述】:

我有一个保存在远程服务器(linux 机器)上的 shell 脚本,我试图在从 windows 执行 SOAPui 的各种测试用例之间调用那个 shell 脚本。 所以我准备了一个 groovy 脚本:

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: Cannot run program "/usr/bin/ssh": CreateProcess error=2, The system cannot find the file specified error at line: 6强>

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

How to execute shell script using soapUI

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

【问题讨论】:

  • 如果您在 Windows 上执行 SOAPUI,则不能使用 /usr/bin/ssh,因为 command.execute() 在本地运行,而在 Windows 中您没有 /usr/bin/ssh .尝试为 Windows 安装 ssh 客户端并在您的命令中使用它。
  • 我知道我们不能使用 /usr/bin/ssh,但我只需要从 windows 中的 soapui 工具执行脚本。那么我将如何从 ssh 客户端执行 windows(如 putty 等)?
  • 我用putty放了一个样本,看看吧:)

标签: groovy ssh soapui


【解决方案1】:

如果您在评论时在 Windows 上安装了 putty.exe,您可以尝试以下操作。

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

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

然后从 SOAPUI 中的 groovy 脚本 调用 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" &gt; /tmp/myfile.txt,请直接使用脚本的路径:/home/test.sh

我从这个nice answer得到Putty命令行选项

希望对你有帮助,

【讨论】:

  • 感谢专家的回答。但是,查询仍然存在,即如果我们通过命令行执行整个soapui套件。该命令将由 Jenkins 发送到一些服务器(新的 windows 机器),这将使我们必须首先安装 putty。如果不从 putty 或一些 ssh 工具运行,还有其他选择吗?
  • @Nikhil 这改变了你原来的问题,因为你原来的问题只是想使用 SOAPUI 远程执行从 Windows 到 Linux 的 shell 脚本......除了在你的评论中你字面上告诉“So how will I able to execute from ssh client for windows(like putty,etc)?”然后我把putty 作为你的一个可能的选择......这个新的约束使 IMO 成为一个新问题。请将此作为一个新问题发布,详细说明所有详细信息:)
猜你喜欢
  • 1970-01-01
  • 2010-12-19
  • 1970-01-01
  • 2015-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
相关资源
最近更新 更多