shell脚本通过进程号停止服务

#!/bin/sh
APP_MAINCLASS=XXXXXXXX.jar
psid=0
 javaps=`ps aux | grep $APP_MAINCLASS|grep -v grep`
  if [ -n "$javaps" ]; then
        echo `echo $javaps | awk '{print $2}'`
      psid=`echo $javaps | awk '{print $2}'`
  else
      psid=0
  fi
  if [ $psid -ne 0 ]; then
      echo "================================"
      echo  "Stopping $APP_MAINCLASS ...(pid=$psid) "
      kill -9 $psid
      if [ $? -eq 0 ]; then
        echo "shutdown success![OK]"
      else
        echo "[Failed]"
      fi
      echo "================================"

  else
      echo "================================"
      echo "warn: $APP_MAINCLASS is not running"
      echo "================================"
  fi

你可能感兴趣的:(小知识点,linux,服务器,运维)