Jaff
Jaff

Reputation: 185

How do I execute a linux command in Jmeter and save the output to a variable?

I have tried using beanshell and groovey and OS proccess sampler but none seem to work for me.

any suggestions would be appreciated

thanks.

Upvotes: 1

Views: 1653

Answers (2)

Ori Marko
Ori Marko

Reputation: 58772

You can add Post processor to OS Process sampler, as Regular Expression Extractor and use Regular Expression as (\w+) to get output

This is assuming you left Standard output empty which will return the output in response data

Standard output (stdout Name of output file for standard output (STDOUT). If omitted, output is captured and returned as the response data.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168082

The easiest would be using JSR223 Sampler like

vars.put('foo', 'your_command_here'.execute().text)

Demo: JMeter Groovy Execution of Command into Variable

More information: Apache Groovy - Why and How You Should Use It

Upvotes: 0

Related Questions