How to use OS Sampler in jmeter for remote script - linux

I am facing an issue in jmeter that I want to know if I can solve.
I need to run a script in distance computer.
when I run the script via command line in my computer it is working.
plink -ssh jenkins#178.27.288.288 -pw passtest sudo /opt/test/test.sh
I want to run it in Jmeter from my computer (the same as the script run).
I tried the ssh sampler that did not work
I want to useage the OS sampler, Is it can be done? Can I run script on distance computer?
The only explanation I found was from blazemeter site, and mentioned:
"Again, since running the “plink” program via the OS Process Sampler is quite easy,"
remote machine: jenkins#178.27.288.288,
password for remote machine: passtest,
command: sudo /opt/test/test.sh
So can someone please advise
I added the OS sampler
and get this message:
Exception occurred whilst executing system call: java.io.IOException: Cannot run program "sudo /opt/test/test.sh" (in directory "plink -ssh jenkins#178.27.288.288 -pw passtest "): CreateProcess error=267, The directory name is invalid
Can someone please advise how to run the command in the remote computer?
once again if I take the full line into command command line it is working, but after I cut it for Jmeter it is not working? what am I missing

Command arguments need to go in the "Command parameters" section, not in the "Working Directory"
I would suggest running your script via cmd.exe interpreter, so the actual command would be cmd, not the Linux command
It is more safe to provide -hostkey parameter as if the remote Linux machine is not in known_hosts your script will get stuck
Assuming all above your OS Process Sampler configuration should look like:
It might be easier to use JSR223 Sampler where you can invoke a program and get the output as easy as:
"c:\somefolder\plink.exe -pw passtest sudo /opt/test/test.sh".execute().text
More information on the approach: Apache Groovy - Why and How You Should Use It

Related

How can I use RobotFramework to sudo in a ssh session where the sudo command doesn't require a password?

I trying to automate a program where I log into a ssh session with a username and password then I'm required to do a sudo su - "username" with no password. I'm able to log into the ssh session with out any problem but I am not able to get the sudo command to work. Looking at the Robot docs you should be able to put none for the password if there is no password but that just seems to cause the program to hang as if it's waiting for the password. The command I tried using is this.
Execute Command su - "username" sudo=True sudo_password=None
I'm not sure if this is a bug with Robot Framework or it simply requires that password to work correctly. I did write a interactive ssh using C where somebody could manually enter the sudo su command then the automation would continue. If anybody has any suggestions for the robot command, or how to possibly execute this using paramiko then I can import that library. Other thought I had was if I can get the C program to work with the robotframework then I can use that. Thank you for any suggestions.
I don't think it's a bug in Robot Framework. It's how the shell in Linux works and has nothing to do with the sudo_password=None.
I'm far from an expert explaining these stuff.
However, Robot Framework SSHLibrary use paramiko exec_command to execute the command.
And as described in the documentation, Execute Command will always be executed in a new shell that is then closed.
SSHLibrary Doc - Execute Command
Let's try run this manually in the command line.
ssh <login_user>#<server_ip> sudo su - <the_su_username>
The command will not give any response and it hangs, just as it will do in Robot Framework and also Paramiko.
If we instead execute a command that will give a response it will work.
ssh <login_user>#<server_ip> sudo ls -ltr
This will work in robot framework as well if you try.
Execute Command ls -ltr sudo=True sudo_password=None
As you say, it works if you use a interactive implementation in C.
I recommend you try implement using an interactive shell in Robot Framework as well.
That will run multiple commands in same shell.
You can find more details here how to use Write and Read.

Executing a Shell Script on Remote Server :: Gives sqlplus: command not found

I have two servers Server A which has a shell script - 'Process_Backup.sh'.
I executed this script on server A - './Process_Backup.sh' and it executed fine. Basically this script connects to my oracle database on Server A and executes a procedure.
What I need to do is execute the script 'Process_Backup.sh' on server A from a different Server B.
I tried following command from Server B
ssh test#server1.xxx.com "cd Scripts/Shell; ./Process_Backup.sh"
But I am getting following error-
line 49: sqlplus: command not found
I have all the software installed on server A so not sure why am I getting this error. I am new to linux environment. I have gone through most of the question posted here but mine seems to be a different case.
Any help is appreciated
Oracle installs a file oraenv that sets some environment variables including the PATH where commands like sqlplus are. That file is included when you start your login shell, the commands to do that were probably created by the installer.
Use
ssh test#server1.xxx.com "source /path/to/oraenv; cd Scripts/Shell; ./Process_Backup.sh"
The file oraenv is probably somewhere below /usr/local.

Ssh command to Windows machine via bash script executed from Jenkins slave

I'm have some bash script (myscript.sh), one of logical steps is to run ssh command against Windows machine running open-ssh.
When I'm running the script (myscript.sh) from the shell everything works fine.
But when I am running same script from Jenkins (CentOS 7.3) it fails to retrieve content via ssh command: ssh root#windows-server hostname.
Please need your help.
The user running the jenkins process do probably not have the correct executable rights or group membership to do so.
Try
sudo -u "jenkinsuser" myscript.sh
If that fails you confirmed the issue.
Change the execute rights on your script or put the server process owner in the right group if this is the case.

Permissions Error in Perl Script for Linux

I'm trying to install the Touchmouse server for Linux. The software is a perl script that I have tried to run via terminal, using the perl command. The software I'm trying to run is here: https://github.com/mycroes/touchmoused
This is the output from terminal:
:~/Desktop/touchmoused-master$ perl touchmoused
Can't open /dev/uinput: Permission denied at touchmoused line 242.
:~/Desktop/touchmoused-master$ Established under name '<name of computer>'
I am new to Linux but have some experience with Terminal.
Thanks!
From the creator of the script:
Just download it, chmod +x and run it (as root, it needs access to /dev/uinput and it wants to register with avahi).
Regards,
http://blog.mycroes.nl/2011/04/touchmoused-logitech-touch-mouse-server.html
Your user won't have permissions for /dev/uinput, also check that /dev/uinput is the correct location for your distribution, the script allows you to override this with the -device flag.
So either make it executable so you don't have to enter 'perl' and then run with sudo or have root run it on startup.

How to create a script on windows which could run ssh command on a remote linux

I just want to create a auto script on windows which could do run some comand through ssh on a reomote linux.
I know it's easy to write script between linux(ssh client) and linux(ssh server).
But I do not know how to create a script on windows(ssh client) to remote connect to linux(ssh server)
If it's just some command lines you want to run then plink will be enough IMHO..
Goodluck.
Most popular languages have ssh libraries you can use, pick a language you are familiar with and then go library hunting.
I've used these with success:
C - libssh
.NET - SharpSSH
Python - Paramiko or Really Simple SSH or Fabric
use plink (get it from putty website) and a bat file format like this:
Plink.exe -ssh -pw %password5 %linuxuser%#%servver% /path/to/script/script.sh
Save em in same folder -> run your awesome masterpiece
One way is to install Cygwin and use a shell script to run ssh commands. You can launch this script by running sh.exe with arguments.
This way, you can do the job with the same Linux tools (sh and OpenSSH) that you are already familiar with.

Resources