Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程

編寫Linux腳本

日期:2017/1/20 17:40:48      編輯:Linux系統常見問題解答

以下是重啟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
Copyright © Windows教程網 All Rights Reserved