linux环境下编写shell脚本实现启动停止tomcat服务的方法
#!/bin/bash
tomcat_home=/home/utry/apache-tomcat-7.0.59_$2
SHUTDOWN=$tomcat_home/bin/shutdown.sh
STARTTOMCAT=$tomcat_home/bin/startup.sh
echo $2 $1 $tomcat_home
#pidlist1=`ps -ef |grep tomcat |grep -v "grep"|awk '{print apache-tomcat-7.0.59_$2}'
#echo $pidlis1t1
case $1 in
start)
echo "启动$tomcat_home"
$STARTTOMCAT
tail -f $tomcat_home/logs/catalina.out
;;
stop)
echo "关闭$tomcat_home"
$SHUTDOWN
pidlist=`ps -ef |grep tomcat |grep -v "grep"|awk '{print apache-tomcat-7.0.59_$2}'`
kill -9 $pidlist
#删除日志文件,如果你不先删除可以不要下面一行
rm $tomcat_home/logs/* -rf
#删除tomcat的临时目录
rm $tomcat_home/work/* -rf
;;
restart)
echo "关闭$tomcat_home"
$SHUTDOWN
pidlist=`ps -ef |grep tomcat |grep -v "grep"|awk '{print $2}'`
kill -9 $pidlist
#删除日志文件,如果你不先删除可以不要下面一行
rm $tomcat_home/logs/* -rf
#删除tomcat的临时目录
rm $tomcat_home/work/* -rf
sleep 5
echo "启动$tomcat_home"
$STARTTOMCAT
#看启动日志
tail -f $tomcat_home/logs/catalina.out
;;
logs)
cd /home/utry/apache-tomcat-7.0.59_$2/logs
tail -f catalina.out
;;
esac