I have a hash.sh file which runs as cron job. Inside the script I need to call pkill to clean some redundant process. But when pkill is called whole script ends up immediately and next commands are not executed. Here is the script with one pkill at the end
#!/bin/bash
cd /opt/selenium-server/
# -c returns number of lines in grep result
countHub=$(ps -x | grep -v "grep" | grep "selenium-server" | grep "role hub" -c)
countNodes=$(ps -x | grep -v "grep" | grep "selenium-server" | grep "role node" -c)
# selenium server jar path
jarFilePath="/opt/selenium-server/selenium-server-standalone-3.141.59.jar"
# if selenium server HUB is in ps -x result
if [ $countHub -eq 1 ]
then
# if there is NO NODE
if [ $countNodes -eq 0 ]
then
# start two new nodes
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
# if there is only ONE NODE
elif [ $countNodes -eq 1 ]
then
# start one new node
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
fi
else # if there is NO HUB start new hub and two new nodes
# kill all possible hubs and nodes for sure
pkill -9 -f "selenium-server"
# Start new hub
java -jar $jarFilePath -role hub &
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
fi
How to write it correctly? Thanks for help.
0 Answers