JMeter get the latest file / contents from SFTP folder - java

I am trying to use JMeter to perform an end to end test. The test involves writing to SFTP folder and reading a file generated as a result of write operation from another SFTP folder.
I am able to connect to SFTP folder using JMeter SSH SFTP plugin and able to successfully write / read SFTP folder contents.
The application under test, creates an output file based on the input file (put by JMeter). The challenge now I have is to read the contents / file which is created on the SFTP folder.
The application under test writes a file with an date-time string which JMeter may not know hence I am trying to read the latest file.
The JMeter SSH SFTP plugin provides a number of options i.e. ls, rm, rmdir, etc however, I have chosen the edit option (${sftp username#servername 'ls -ltr /server/path | tail -n 1'}) and tried to use the following in order to read the file however, I neither see error nor response.
I would appreciate any pointers and if you can think of a better solution. Please also let me know if you would like me to share more information.
Thanks in advance.

You're using the wrong sampler, if you want to run a command you need (surprisingly) SSH Command Sampler
This pipe symbol | is not a parameter for ls command, it's a part of Unix shell, in majority of cases it would be bash so you need to amend your command to look like:
/bin/bash -c "ls -ltr /server/path | tail -n 1"
example SSH Command Sampler configuration:
and example output:
More information: How to Run External Commands and Programs Locally and Remotely from JMeter

Related

Installing Software via SSHJ results in exit code 127

I am trying to write a software to automatically install Linpack on a CentOS Server.
Here's the code I've been working with so far
First, I upload 2 zip files to the SFTP Server that's running on CentOS, which works fine.
Then I extract those 2 files using the commands tar xfv l_mklb_p_2020.2.001.tgz and tar xfv l_mpi_2019.8.254.tgz which also work as intended.
Then I try to cd l_mpi_2019.8.254 into the extracted folder to execute ./install.sh
However, this is where my program fails. I get the exit code 127, which would imply that the command does not exist/can't be found
Executing these commands in the same order manually over PuTTy works just fine though, so I am unsure why it isn't working in my program. Maybe the / gets escaped so the command that's executed is .//install.sh? How would I check for that though? Does anyone have any ideas?

Could not open jmx file while running JMeter command line

I have run a thread group in JMeter in GUI mode it is working and getting results, but while running same ThreadGroup.jmx file through terminal(Non GUI] mode,I am getting an error Couldn't load .jmx file.
Can anybody suggest me how to resolve the issue.
In linux using files is case sensitive, so use exact letters(as sampleThreadGroup.jmx)
Also make sure the file is saved in the correct folder
And check your user have permission to execute it (try chmod 777 for jmx file)

How do I make my directory give the executable permissions to script files which are going to be created by my Java program?

I want my directory to give executable permissions (by default) to all the shell scripts which are going to be created in that directory after I run my Java program. I tried the following commands:
setfacl -d -m group:name:rwx /path/to/your/dir
find ./ -name "*.sh" -exec chmod +x {} \;
The first one is not showing any response while the second one works fine but I have to execute this command manually in terminal after my Java program has created all the scripts. This is not what i seek. I want this thing to be automatic. Here is what I am trying to achieve:
My Java program creates the .sh files in a directory.
Now the program would try to execute this script file.
Here is a Java code snippet which shows how it is going to execute the script files:
ExecuteShellComand obj = new ExecuteShellComand();
String command2 = "./script.sh";
String output2 = obj.executeCommand(command2);
It doesn't run unless I give the executable permissions to the script.sh. How do I do it? Is there any way around it? If I am not doing something in a way it should be done, feel free to give your suggestions. Thanks
Default ACL permissions are masked by the file's creation mode as specified in open and mkdir syscalls.
Since files are usually created with a default mode of 0666, execute permissions will be masked instead of inherited.
It's the responsibility of the program that creates the files to create them with the right permissions. If you set the permissions correctly when creating the scripts, you won't need ACL or chmod at all. The best way to fix this would be for your program to set the mode in the open call to 0777.
Java appears to have Files.createFile for this. Additionally, you have a more fuzzy File.setExecutable to do it after the fact, which is not Unix canonical behavior, but probably fine for your use case.

copy directory operation using linux command in java

I want to write a java code that executes Linux command to copy a directory from server to another server.I got a directory which contains sub directories and files. So I need to copy all these contents to another server. How can I use Linux command for that purpose in java.
Thanks a lot!
You could look at these good post's here
The only thing that would change is command. there user was asking for diff, here you are asking to copy between two machines. I am assuming you could do passwordless ssh from your source machine to destination and if that's the case you could use scp command to copy the directory like below:
scp -r /home/test/blah imauser#thathost:/home/test/destination/directory
-r will recursively copy directories as well to your existing directory as above on thathost.

How to run Java programs over ssh?

Let's say I make a Java project in Eclipse that has 3-10 classes and one of which has a main(String[] args) method that starts the whole program and takes 4 arguments at the command line. Let's also say that this project has 6-10 .jar files in src/lib that it needs to run.
If I have ssh access to another computer (UNIX on both ends) and I want to run this program, how exactly do I go about doing so?
I ask because I have been doing some distributed computing projects and I need to run my program on multiple machines but I am a total command line noob and I don't have physical access to all of the machines.
Edit:
Seems I need to SCP the files over. Can someone show me the particular command that makes the Java program run? Including what directory I should run it from and how to include the JAR dependencies.
to run
java -jar thejarfile.jar "arg1" "arg2" "ectect.."
if you want to run it in the background java -jar thejarfile.jar "arg1" "arg2" &
to kill it if its in the background ps -aux to get the id and then kill (id number)
In general, you use ssh to log into a remote computer, and then you run programs from that machine's storage, using that machine's resources.
So if you want to run your Java program on a different machine, you'd need to copy the required files there, then ssh to that machine and run the program from the remote command line.
You write a tiny bootstrap program that will be your MicroKernel. You SCP that MicroKernel to the remote machine. This program will use a custom ClassLoader to pull the rest of the dependencies for your real application down into memory or some storage onto the remote machine. Look into the URL ClassLoader for some help as it can load JAR files from HTTP addresses.
Or you can just zip up your whole program, SCP it to the remote machine, unzip it then run 'java' like normal. If you have SSH access you should have access to scp files onto that machine. If not you can always SSH into the remove machine then scp them from your machine.
Example:
ssh myname#myremotemachine
> mkdir /location/to/program
> scp myname#mydevmachine:/location/to/program/* /location/to/program
This all works really well if you have your SSH keys setup properly and don't have to put in a password.

Categories

Resources