首页 > 学院 > 网络通信 > 正文

编写Linux脚本

2019-11-03 23:05:27
字体:
来源:转载
供稿:网友

  以下是重启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

  fi


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表