I'm facing problem while running a script 'restart.sh'. Its main objective is to kill a process by id, and restart the process again.
The process name has 'DND' as below
$ ps -ef | grep DND
root 18425 1 60 11:53 pts/0 00:40:34 java -jar DND_Retry.xml
NOTE : The PID will be changed every time the script is executed.
1 part of script given below:
echo "Killing BND Process"
pids=$(pgrep -f BND)
for pid in "${pids}"; do
if [[ $pid != $$ ]]; then
kill -2 "$pid"
fi
done
sleep 2
while true
do
shut1=`more /Data/v3/nohup_bnd.out | grep "has been shutdown" | wc -l`
if [ $shut1 -eq 1 ]; then
echo "process ended now restart"
The problem is: The script executes successfully first time but, when I execute again, it doesn't kill the process. However if I kill the process manually with Kill -9, and again execute the script it executes successfully and produce the desired result.
Is there anything I need to modify in above script/condition. I need to perform Kill -2.
ps
depending on how it was started? (I can't see where your script would restart the program). Also, you haveBND
in the script, andDND
in the sampleps
output and in the text. Is that relevant or just a typo?