Need help converting batch file to linux shell script - linux

I am switching my server's hosting provider from Windows Server to Linux Debian and I need help to convert my Run.bat to an executable shell script.
The Windows batch file:
java -cp bin; deps/mail.jar; deps/xstream.jar; deps/xpp3-1.1.4c.jar;
deps/scheduling.jar -server server.Server
When I save this as a shell script it does not properly run when I "Run in terminal", the shell just opens and closes immediately.

In linux, the separator is : instead of ;, so try this instead:
$ java -cp bin:deps/mail.jar:deps/xstream.jar:deps/xpp3-1.1.4c.jar:deps/scheduling.jar -server server.Server
Copy the command without the $. The $ is used to indicate the command belongs in a linux shell.

Related

How to make Jmeter run command from CMD - OS sampler - JMETER

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

Using a batch file through Linux subsystem on Windows 10?

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.

How to launch a shell script make with Linux on Windows

I have a shell script make with Linux with this code:
#!/bin/sh
awk '{ print $3,$2,$4,$1}' df_real_credit_network_B0.00_BC0.00_l33.33_day1 > credit_adj
awk '{ print $3,$2,$5,$1}' df_real_interbank_network_B0.00_BC0.00_l33.33_day1 > interbank_adj
The script creates two objects: "credit_adj" and "interbank_adj", necessary for others scripts for the software R. Obliviously Windows don't recognize the script, so I try to modify the extension ".sh" with ".bat" and I deleted the string "#!/bin/sh" from the script.
In this way the two objects are created but are empty, because windows don't recognize the instruction awk.
How can I create the two objects correctly?
Thanks
You cannot directly run a Unix shell script in windows, One way to run unix/Linux shell script in windows is , install cygwin in windows and run script inside cygwin

Do we need to modify .sh file while executing in Windows?

I have one .sh file which runs well on MAC system. I want to run the same .sh file on windows using CYGWIN. My question is, Do I need to make any modification in the commands while using it in Windows system with CYGWIN? Please help.
e.g. I have the following commands in .sh file-
export ML_SERIALIZE_DIR=/Users/Mxyz/ML
export ML_SERIALIZE_GRAPH=true
echo ML_SERIALIZE_DIR = $ML_SERIALIZE_DIR
echo ML_SERIALIZE_GRAPH = $ML_SERIALIZE_GRAPH
java -DCL_LOG_DIR="/Users/Mxyz/ML" -classpath .:lib/:Ml-mobxyz-import.jar org.xy.mobxyz.mobxyz.ML
echo "Batch program is complete"
No need to change anything but make sure that all required binaries by your .sh must be there in CYGWIN

Running a command in shell script

I have a shell script file (run.sh) that contains the following:
#!/bin/bash
%JAVA_HOME%/bin/java -jar umar.jar
when i try to run it (./run.sh), it gives me following:
umar/bin/run.sh: line 1: fg: no job control
However if I run same command directly on shell, it works perfectly.
What's wrong with the script file?
Thanks
%foo% is not how you do command substitution in a bourne/BASH shell script. I assume you're running this from a Windows command line, which is why it works when you run it directly. Try using proper bourne syntax:
${JAVA_HOME}/bin/java -jar umar.jar
Try turning on monitor mode
set -m
%JAVA_HOME% will substitute a Windows environment variable and is appropriate in a .bat file.
Try the following shell script which should work on most UNIX like systems.
#!/bin/bash
$JAVA_HOME/bin/java -jar umar.jar

Resources