I am struggling with jmeter for running cmd command to remote desktop.
I use the OS sampler.
I have a command that if I run it from the command line from my computer it worked, but when I try to make jmeter to run it, it failed - I use the same computer.
the command is:
plink -ssh jenkins#178.27.288.288 -pw passtest sudo /opt/test/test.sh
I added an OS sampler as followed:
the working directory is the cmd.exe directory.
and the command is the full command I want jmeter to run, the same one that working perfectly on cmd direct.
I get this error:
Response message: Exception occurred whilst executing system call: java.io.IOException: Cannot run program "plink -ssh jenkins#178.27.288.288 -pw passtest sudo /opt/test/test.sh" (in directory "c:\windows\system32"): CreateProcess error=2, The system cannot find the file specified
I do not know which file jmeter wants, I just want him to run the command, to connect to remote computer and run the command, the command working perfectly in command line and run the script in the remote computer.
I found this blog in the net:
https://www.blazemeter.com/blog/how-run-external-commands-and-programs-locally-and-remotely-jmeter
that said that it can be done, but since it is easy they not displayed step by step instructions.
when I change the command to dir, it run OK and the results are like I write dir in command line.
How can I make jmeter open the command line and just put the command and press enter, and display the results?
In the command you need to give the name of the programme to execute. In case of command prompt it is cmd.exe and for shell i think it is powershell.exe
Rest need to be pass as command parameters.
Check below for command parameters:-
The OS Process Sampler is a sampler that can be used to execute
commands on the local machine. It should allow execution of any
command that can be run from the command line. Validation of the
return code can be enabled, and the expected return code can be
specified. Note that OS shells generally provide command-line parsing.
This varies between OSes, but generally the shell will split
parameters on white-space. Some shells expand wild-card file names;
some don't. The quoting mechanism also varies between OSes. The
sampler deliberately does not do any parsing or quote handling. The
command and its parameters must be provided in the form expected by
the executable. This means that the sampler settings will not be
portable between OSes.
Many OSes have some built-in commands which are not provided as
separate executables. For example the Windows DIR command is part of
the command interpreter (CMD.EXE). These built-ins cannot be run as
independent programs, but have to be provided as arguments to the
appropriate command interpreter.
For example, the Windows command-line: DIR C:\TEMP needs to be
specified as follows:
Command: CMD Param 1: /C Param 2: DIR Param 3: C:\TEMP
If the commands are remote commands then try with "Remote Commands: Linux/MacOSX" with SSH sampler shown in the blog you shared.
Below screenshot for simple execution of dir command:-
--update--
additional screenshots
to execute a windows commad DIR c:\test use below settings
Related
I've found a very strange issue, when in linux terminal I type "enable -n trap", it would disable the trap linux builtin command. But if I put it into a script like
#!/bin/bash
enable -n trap
and then run the script, there's no error but the command is also not disabled. Really appreciate if someone could share what is happening and how to run it in some file instead of directly in the terminal. Thank you!
The enable command only affects the current shell. When you run a script, that script is executed in a new process, so:
A new shell starts
The enable command runs and disables the trap command in that shell
The shell exits
If you want to affect the current shell, your only option is to source the script using the . (or source) command. If the script is named disable-trap.sh and is in your $PATH, you can run:
. disable-trap.sh
You can also provide a full path to the script:
. /path/to/disable-trap.sh
Sourcing a script like this is largely equivalent to typing the same commands in at the command line: it executes the instructions in the script in the current shell, rather than spawning a new process.
I have a batch file that bashes into the linux subsystem I have on Windows 10 that tries to execute commands via the linux system. However, it doesn't execute any commands after the bash command. Here is an example:
bash
cd Documents/CS/DS
This just bashes into whatever directory the file is run from instead of CS/DS consistently. Is there anyway to have the batch file execute the rest of the commands?
When you run bash like that, you are sending execution into that executable. Launch bash as a separate process:
`start "bash" bash.exe`
Bash won't execute the rest of your cmd script. Cmd.exe processes cmd/bat files, bash only executes bash commands and scripts.
I have shell script which is kept on remote server(linux machine) and I am trying to call that shell script in between the execution of various test cases of SOAPui from windows.
So I have prepared a groovy script:
def command="/usr/bin/ssh -p password username#IP_address bash -s < /home/test.sh"
def proc=command.execute().text
proc.waitFor()
But unfortunately, I am receiving an error:
java.io.IOException: Cannot run program "/usr/bin/ssh": CreateProcess error=2, The system cannot find the file specified error at line: 6
I tried to search more on this, but couldn't get the resolution. Some of the links were:
How to execute shell script using soapUI
http://groovy-lang.org/groovy-dev-kit.html#process-management
If as you comment you've a putty.exe installed on Windows you can try with the follow.
First of all create a file in your Windows local with the commands to execute remotely for example I create the follow C:/temp/commandsToRunRemotely.txt then in this file put the command you want to execute. As a sample I use the follow command:
echo "test remote execution" > /tmp/myfile.txt
Then from groovy script in SOAPUI call putty.exe passing the local file which contains the commands to execute remotely:
def command = "C:/path/to/putty.exe -ssh user#IP -pw pass-m C:/temp/commandsToRunRemotely.text"
def proc = command.execute()
proc.waitFor()
Note that if you've putty.exe in your Windows path, you can simply use putty.exe instead of full path.
This is only an ilustation sample, but if you want to execute a shell script remotely instead of echo "test remote execution" > /tmp/myfile.txt in the commands file use directly the path for your script: /home/test.sh
I get the Putty command line options from this nice answer
Hope it helps,
I'm running a batch file (export.bat) in Windows 7 using plink to execute a script in a remote Linux server machine, but I get this error:
./test.sh: line 3: back.sh: command not found
Batch file:
#echo off
cls
plink 1.1.10.11 -l user -pw pass "bash ./test.sh"
Script in the remote server:
#!/bin/sh
cd /path/path/path
script --table filename--filebase /path/path/path/path
exit
I'm assuming script in your remote script is actually back.sh, and that it exists in /path/path/path.
To execute a script back.sh in the directory you cd to (i.e. the current directory), use ./back.sh instead of just back.sh.
PS: You should generally try to avoid sanitizing input and output of things you post on StackOverflow. It often ends up confusing. For example, you say you get the error line 3: back.sh: command not found, but your remote script does not contain the command back.sh on line 3 or anywhere.
Instead, invest 15 minutes in making a runnable test case with no sensitive data, that you can actually execute and copy files and errors from verbatim. The bash tag wiki has tips for this.
If I open a shell into a machine with: putty -load session_name and then execute a command to add a job to a Grid queue on a linux system (qsub -cwd -b hostname), everything works fine.
But if I add the command to a text file, and then do putty -load session_name -m file.txt, I get qsub: command not found
If I back out and simplify the text file to be only the command hostname and use the -m option, it also works fine.
If I use the Connection->SSH->Remote command, and do something similar as the -m command, I get the same results as from the command line.
I'm very much a novice at linux systems, and this seems like it should be a simple fix to tell something that 'qsub' exists somewhere. Either that or there are some restrictions on these remote access things...
Edit:
Ok, so the initial question was how to run it--and I figured that out (add an absolute path), but there are other environment variable issues as well. It appears that qsub requires the SGE_ROOT variable to be set, but that isn't set for the remote commands window either.
So, a better question is, how do I get the putty remote commands shell (using -m) to open with the same properties and setup as a manual command line shell?
qsub is on your path when you log in interactively, but in the non-interactive shell it is not. Give the full path in the script, or set PATH in the script, and you ought to fix your problem.
It seems you need to run your command in the context of an interactive session, but the sshd protocol doesn't directly do that. So try invoking the command indirectly through /bin/sh.
/bin/sh -i -c "qsub -cwd -b hostname"
The -i makes the shell initialize itself like an interactive one, so it will load all the environment variables in your .profile or .bashrc that are loaded in a real interactive shell. The -c provides a command to run within that interactive shell.
You shouldn't have to explicitly set any paths this way since it works in an interactive session.