bash 在 jmeter 中运行 sh 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30596880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run sh script in jmeter
提问by KingKoelsch
For load testing I want to randomize my testvalues before I run the test in jmeter. To do so, I want to use this bash script:
对于负载测试,我想在 jmeter 中运行测试之前随机化我的测试值。为此,我想使用这个 bash 脚本:
#! /bin/bash
cat data.dsv | shuf > randomdata.dsv
This should be executed in jmeter. I tried using a BeanShell Sampler with this command (I am using this command to always find the correct paht to the file no matter on which machine I want to execute it):
这应该在jmeter中执行。我尝试使用带有此命令的 BeanShell Sampler(无论我想在哪台机器上执行它,我都使用此命令始终找到文件的正确路径):
execute(${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}random.sh)
but I always get this error message:
但我总是收到此错误消息:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``execute(/home/user/git/path/'' Encountered "( /" at line 1, column 8.
Any Ideas what to do or is there some best practice I just di not found yet?
有什么想法该怎么做,还是有一些我还没有找到的最佳实践?
回答by Dmitri T
I would suggest going for OS Process Samplerinstead, it should be easier to use, something like:
我建议改用OS Process Sampler,它应该更易于使用,例如:
In regards to Beanshell approach, there is no need to us __Beanshell function in the Beanshell sampler, besides an instance of Beanshell interpreter is created each time you call the function causing performance overhead. You can just put the code into sampler's "Script" area as
对于 Beanshell 方法,不需要在 Beanshell 采样器中使用 __Beanshell 函数,此外每次调用该函数时都会创建一个 Beanshell 解释器实例,从而导致性能开销。您可以将代码放入采样器的“脚本”区域
import org.apache.jmeter.services.FileServer;
StringBuilder command = new StringBuilder();
FileServer fileServer = FileServer.getFileServer();
command.append(fileServer.getBaseDir());
command.append(System.getProperty("file.separator"));
command.append("random.sh");
Process process = Runtime.getRuntime().exec(command.toString());
int returnValue = process.waitFor();
return String.valueOf(returnValue);
See How to use BeanShell: JMeter's favorite built-in componentguide for information on Beanshell scripting in JMeter.
有关JMeter 中Beanshell 脚本的信息,请参阅如何使用 BeanShell:JMeter 最喜欢的内置组件指南。