技术员联盟提供win764位系统下载,win10,win7,xp,装机纯净版,64位旗舰版,绿色软件,免费软件下载基地!

当前位置:主页 > 教程 > 服务器类 >

编写Linux脚本

来源:技术员联盟┆发布时间:2018-06-24 18:09┆点击:

  以下是重启Linux下某进程的shell脚本,以tomcat进程为例:

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