技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁(yè) > 教程 > 服務(wù)器類 >

編寫Linux腳本

來源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2018-06-24 18:09┆點(diǎn)擊:

  以下是重啟Linux下某進(jìn)程的shell腳本,以tomcat進(jìn)程為例:

  #!/bin/sh

  pid=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`

  if [ "$pid" = "" ] ; then

  echo "tomcat service does not start!"

  else

  kill -9 $pid

  pid1=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`

  if [ "$pid1" = "" ] ; then

  echo "Successfully kill tomcat processes: " $pid

  else

  echo "tomcat kill process failed!"

  exit 1

  fi

  fi

  rm -rf /opt/tomcat/work/*

  ./startup.sh

  pid2=`ps -ef|grep tomcat|grep -v grep|awk '{print $2}'`

  if [ "$pid2" = "" ] ; then

  echo "tomcat service failed to start!"

  else

  echo "tomcat service starts successfully:" $pid2