I need to terminate a process and restart it using the same command used to start it. Have done it using the below commands.
But the problem is the command that I receive is different from the original command that is used to start. Original command is having quotes and the command that I receive is without quotes. So It is not getting started.
I don't know why? can anyone help me in resolving this...
Script below:
processes=$(ps aux | grep $1 -i | grep -v grep | grep -v sh | awk '{print $2}')
cntr=0
for i in $processes; do
cmd=$(cat /proc/$i/cmdline | tr '\000' ' ')
kill $i;
cmds[$cntr]=$cmd
cntr=$cntr+1
done
#Restart the process
echo "Commands: " $cmds
for cmd in $cmds; do
echo "Starting..." $cmd
eval "$cmd"
done
Original command: "/apps/test/bin/" xxxxx
My Command: /apps/test/bin xxxxx