Here are the 3 scripts(FirstScrpt.sh,firstcallScrpt.sh,startProcess.sh) that were running in the server for the past several years.
I understand the way it is written is that for every 1 hour 'firstcallScript.sh' is being called in that it kills the pid of 'startProcess.sh'
and starts again.
2 things I noticed
Value of pid.txt never changes if it is being is killed and created every hour.
It never runs in the background even when it is run with '&' like (./FirstScrpt.sh &)
FirstScrpt.sh
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 test|prod"
exit 1
fi
envRun=$1
echo "Level is : ${envRun}"
while [ 1 ]
do
cat pid.txt | xargs -l1 kill
./firstcallScript.sh ${envRun}
sleep 3600
done
firstCallScript.sh
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Usage: $0 test|prod"
exit 1
fi
envRun=$1
if [ $envRun = "test" ]
then
echo "Level is : ${envRun}"
./startProcess.sh ${envRun}
else
echo "Level is test Invoke test script : ${envRun}"
./startProcess.sh ${envRun}
fi
startProcess.sh
#!/bin/bash
envRun=$1
echo "${envRun}"
echo "I'm a Linux user."
echo $! > pid.txt
In StartProcess.sh you only set an environment variable and echo a couple of messages. $! is supposed to be the PID of the last command run in the background, but nothing is being run in the background.
So are you saying that if you type ./FirstScrpt.sh & that the prompt doesn't return and the script has to be killed (or CTRL-C) to get control back to your invoking shell?
In StartProcess.sh you only set an environment variable and echo a couple of messages. $! is supposed to be the PID of the last command run in the background, but nothing is being run in the background.
I removed a line of code to post here. It actually calls a process /opt/$[folderpath}/bin/java ${JAVA_OPTIONS} WregProcessor.jar > /dev/null 2>&1 &
So are you saying that if you type ./FirstScrpt.sh & that the prompt doesn't return and the script has to be killed (or CTRL-C) to get control back to your invoking shell? Yes
For Sea: the code is below is typed 2 times is this how it should be ?