Run sh script in jmeter

For load testing, I want to randomize my test values ​​before running the test in jmeter. For this, I want to use this bash script:

#! /bin/bash
cat data.dsv | shuf > randomdata.dsv

      

This should be done in jmeter. I tried to use the BeanShell Sampler with this command (I use this command to always find the correct file in the file no matter what computer I want to run it on):

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 haven't found yet?

+3


source to share


1 answer


I would suggest it would be easier to use instead of OS Process Sampler , for example:

OS Process Sampler Example Configuration

In terms of the Beanshell approach, we do not need the __Beanshell function in the Beanshell sampler, in addition, the Beanshell interpreter is instantiated every time you call the function that calls the overhead. You can simply place the code in the "Script" sampler area as



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 Component for information on Beanshell scripting in JMeter.

+5


source







All Articles