Shell commands working from PuTTy but not from Shell script File - shell

I am trying to execute the below shell commands from PuTTY
PACKAGEPATH=/data/dev/bwan/deliveryPackage
RELEASENAME=R201709TEST3
PACKAGEFINALPATH=$PACKAGEPATH/$RELEASENAME
echo $PACKAGEPATH
echo $RELEASENAME
echo $PACKAGEFINALPATH
and I get the desired output as
/data/dev/bwan/deliveryPackage
R201709TEST3
/data/dev/bwan/deliveryPackage/R201709TEST3
However, If I am putting the same steps in a shell File and then executing that shell Script, it is giving me unexpected responses as
/data/dev/bwan/deliveryPackage
R201709TEST3
/R201709TEST3n/deliveryPackage
Why is this happening?

Related

Problem in subcommands of the Bash Script

I had the bash script where in I had to launch the application ide command and then the >>> appears in the terminal where in I had to execute the commands such as in script file
#!/bin/bash
OMShell-terminal
loadModel(Modelica)
loadFile("Filename")
simulate(filename, startTime, stopTime)
but after loading the OMShell-terminal I will get the >>>to input the commands here but the shell script would not let me to input the commands here from shell script itself what modification I should do please guide.

How to debug a tcsh script and put the debugged output in a file?

I want to debug my tcsh script. Like in sh script if we add set command with -x then it prints the execution of script.
#! /bin/sh
set -x
exec 2>/usr/bin/error.log
#My script code
And I tried this as explained here . But still don't know how to print in a file? I am writing below code:
#! /bin/tcsh
set echo
exex 2>/usr/bin/error.log
I am getting permission denied error.I have also tried running as root still same error. But that can be the error in my script. So I want to check in error.log where does the error occur. But after I run script the error.log file is not getting generated. Is there any other way to write stderror for tcsh? Can we use exec command in tcsh?
Also are tcsh and csh both same things or different?

Run bash script loop in background which will write result of jar command to file

I'm novice to running bash script. (you can suggest me, if title I've given is incorrect.)
I want to run a jar file using bash script in loop. Then it should write the output of jar command into some file.
Bash file datagenerate.sh
#!/bin/bash
echo Total iterations are 500
for i in {1..500}
do
the_output="$(java -jar data-generator.jar 10 1 mockData.csv data_200GB.csv)"
echo $the_output
echo Iteration $i processed
done
no_of_lines="$(wc -l data_200GB.csv)"
echo "${no_of_lines}"
I'm running above script using command nohup sh datagenerate.sh > datagenerate.log &. As I want to run this script in background, so that even I log out from ssh it should keep running & output should go into datagenerate.log.
But when I ran above command and hit enter or close the terminal it ends the process. Only Total iterations are 500 is getting logged into output file.
Let me know what I'm missing. I followed following two links to create above shell script: link-1 & link2.
nohup sh datagenerate.sh > datagenerate.log &
nohup should work this way without using screen program, but depending on your distro your sh shell might be linked to dash.
Just make your script executable:
chmod +x datagenerate.sh
and run your command like this:
nohup ./datagenerate.sh > datagenerate.log &
You should check this out:
https://linux.die.net/man/1/screen
With this programm you can close your shell while a command or script is still running. They will not be aborted and you can pick the session up again later.

how to run a script and keep result in a variable in a remote shell script

I wrote the following script in a .sh file:
#!/bin/bash
ssh root#192.168.10.10 "a=`ps -ef`;echo $a";
run it and get error lines like "bash: root: command not found...", what's wrong in "a=`ps -ef`;echo $a"?
Thanks
Try something like :
local a
a = $(ssh root#192.168.10.10 "echo ps -ef;")
This way, you are executing echo after ssh, and then store the result of this command in a.

How to open a new terminal by commands in a shell scripts?

I have two set of commands to be executed from different directories from a shell script.
My content of the shell script is below:
echo "starting Windshaft cartodb..."
cd /home/user/Windshaft-cartodb/
node app.js development
echo "Windshaft cartodb started."
echo "starting CartoDB SQL API..."
cd /home/user/CartoDB-SQL-API/
node app.js development
echo "CartoDB SQL API started."
When I run the shell script file, the first 3 commands were running successfully. In order to run the next commands, I have to stop the previously running command by pressing Ctrl + C. Script processing continues with echo "Windshaft cartodb started." only after doing this.
My problem is: Without stopping the previously running commands, I need to execute the commands after the below commands in a new terminal.
echo "starting Windshaft cartodb..."
cd /home/user/Windshaft-cartodb/
node app.js development
How to open a new terminal by commands in a shell script?
How to open a new terminal by commands in a shell script?
You can open a new terminal with the command xterm and run a program in it with its option -e:
xterm -e node app.js development&

Resources