码迷,mamicode.com
首页 > 系统相关 > 详细

编写Linux脚本

时间:2014-07-24 10:28:03      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:linux   shell   

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

编写Linux脚本

标签:linux   shell   

原文地址:http://blog.csdn.net/gao715108023/article/details/38079077

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!