[Shell] 针对脚本运行的控制脚本

#####################################################
# funciton:控制TEST.sh脚本
#	参数:$1:-s biz_date 启动 -e 停止 -f 查看进程 -h 帮助
#	      $2:bizdate
# author:ebda.zh
# date:20160525
#####################################################
#!/usr/bin/sh
TEST_HOME=/home/ap/lw/
BIZDATE=${2}
HOSTNAME=`hostname`
echo "current hostname"${HOSTNAME}

if [ $# -eq 0 ]
then
	echo "location01.参数错误!"
	echo " -h 帮助"
	exit 1
fi

_tmp=${TEST_HOME}/logs/ebdmControl_tmp.$$
user=`whoami`

if [ $1 = -s ]
then
	ps -ef|grep TEST.sh|grep $user|grep -v "grep"|grep -v "vi"|grep -v "view">$_tmp
	tx=`wc -l $_tmp | awk '{print $1}'`
 	if [ $tx -gt 0 ]
        then
     	echo "$0已经有进程启动!";
	rm -f $_tmp;
	exit 0;
fi;
	rm -f $_tmp;
	echo "$0启动!"
	nohup ${TEST_HOME}/sbin/TEST.sh ${BIZDATE} &
        sleep 2
	exit 0;
	
elif [ $1 = -e ]
then
   bl=`ps -ef|grep 'TEST.sh'|grep $user|grep -v "grep"|grep -v "vi" | grep -v "view" |
       grep -v "\-e"| awk '{print $2}'`
	for d in $bl
	do
        kill -9 $d
	done
	echo $0已停止!
elif [ $1 = -h ]
	then
        echo "功能:控制ebdm_monitor.sh!"
        echo " -s 启动程序!"
        echo " -e 程序停止!"
        echo " -f 查看是否有进程正在运行!"
        echo " -h 帮助!"
elif [ $1 = -f ]
then
        ps -ef|grep 'ebdm_monitor.*sh'|grep $user|grep -v "grep"|grep -v "vi"|grep -v "view"
else
        echo "location02.参数错误!"
        echo " -h 帮助!"
fi
分类上一篇:无,已是最新文章    分类下一篇:

Leave a Reply