#!/bin/bash appName="appName" appPsCommond="appPsCommond" appPath="/home/appPath" isRunning(){ appPs=`ps -ef | grep "$appPsCommond" | grep -v "grep" | grep -v "stop" | awk ' { print $appPsCommond} '` if [ "$appPs" ] then return 0 fi return 1 } invokeStop(){ if ! isRunning then echo `date` `whoami` INFO: "the $appName is not running." >> /home/shellLog echo "the $appName is not running." exit 1 fi if [ ! -d $appPath ] then echo `date` `whoami` INFO: "$appPath not exist." >> /home/shellLog echo "$appPath not exist." exit 1 fi for pid in `ps -ef | grep $appPsCommond | grep -v grep | grep -v stop | awk ' { print $2 } '` do kill -9 $pid; echo `date` `whoami` INFO: "killed pid: $pid ." >> /home/shellLog echo "killed pid: $pid ." done } if [ -z "$1" ] then echo `date` `whoami` INFO: "command error.usage:$appName stop." >> /home/shellLog echo "command error. usage:$appName stop." else case $1 in stop) invokeStop ;; *) echo `date` `whoami` INFO: "command error.usage:$appName stop." >> /home/shellLog echo "command error. usage:$appName stop." ;; esac fi
通用kill shell外壳
猜你喜欢
转载自ring-feng.iteye.com/blog/1171151
今日推荐
周排行