简体   繁体   English

如何在Jmeter中运行Shell脚本-Groovy

[英]How to run shell script in Jmeter - Groovy

I am trying to run script on remote computer using groovy in jsr223 sampler in jmeter. 我正在尝试在jmeter的jsr223采样器中使用groovy在远程计算机上运行脚本。 The problem that I do not get any response if the script success or not, or even if it success login or any indication. 如果脚本成功与否,即使成功登录或任何指示,我也没有得到任何响应的问题。 to be sure that this behavior occurred all the time, I created imaginary script and run it, and still nothing in response. 为确保这种行为一直发生,我创建了一个虚构的脚本并运行它,但仍然没有任何响应。 here is the script 这是脚本

"c:/Program Files/PuTTY/plink.exe jenkins@174.257.244.157 -pw test!67  sudo /opt/mew/run_me.sh".execute().text

the server and the password are fake. 服务器和密码是假的。 but in the real script they are real. 但是在真实的脚本中它们是真实的。 can someone please advise? 有人可以请教吗? the plink.exe destination is correct, if I use '\\' instead of '/' it failed so I just change the directions. plink.exe目的地是正确的,如果我使用'\\'而不是'/',它将失败,因此我只是更改方向。

but their is no way to know what happened, I want to do it via code and with no jmeter sampler that I faced difficulties. 但是他们无法知道发生了什么,我想通过代码来实现,并且没有遇到困难的jmeter采样器。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

I can think of 3 reasons for not returning anything 我可以想到不退货的3个原因

  1. You're being asked to add your 174.257.244.157 to the SSH Known Hosts 系统要求您将174.257.244.157添加到SSH已知主机
  2. You're being asked for the password of your jenkins user for sudo command execution, if this is the case add the jenkins user to sudo group and configure it to be able to run commands without prompting for password 系统会要求您jenkins用户的密码以执行sudo命令,如果是这种情况,请将jenkins用户添加到sudo组并将其配置为能够在不提示输入密码的情况下运行命令
  3. Your /opt/mew/run_me.sh does/outputs nothing, try adding something like echo "Starting..." to the beginning to have at least some output. 您的/opt/mew/run_me.sh不会执行/输出任何操作,请尝试在开始处添加诸如echo "Starting..."之类的内容,以至少具有一些输出。 Or substitute it with some command which is guaranteed to work like ls or whoami or date 或者用保证像lswhoamidate这样的命令来代替它

In order to get more idea of what's going on you can amend your Groovy script to use ProcessBuilder class like: 为了了解发生了什么,您可以修改Groovy脚本以使用ProcessBuilder类,例如:

new ProcessBuilder("c:/Program Files/PuTTY/plink.exe jenkins@174.257.244.157 -pw test!67  sudo /opt/mew/run_me.sh").inheritIO().start().text

More information: Apache Groovy - Why and How You Should Use It 更多信息: Apache Groovy-为什么以及如何使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM