cron 脚本中的 pkill 会终止下一个命令

cron 脚本中的 pkill 会终止下一个命令

我有一个作为 cron 作业运行的 hash.sh 文件。在脚本中,我需要调用 pkill 来清除一些冗余进程。但是当调用 pkill 时,整个脚本会立即结束,并且不会执行后续命令。以下是末尾有一个 pkill 的脚本

#!/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

如何正确书写?谢谢帮助。

相关内容