-bash-4.1# cat tomcat.sh
#!/bin/bash
#date 2016-06-17
#Author ouyang
#
usage () {
echo -e "\033[35mUsage: $0 [start|stop|status|restart]\033[0m"
}
tomcat_start () {
/usr/local/tomcat/bin/startup.sh
}
tomcat_status () {
STAT=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
if [ ! -z $STAT ];then
echo -e "\033[32mTomcat is Running...\033[0m"
else
echo -e "\033[33mTomcat is not Running...\033[0m"
fi
}
tomcat_stop () {
TOM_PATH=/usr/local/tomcat
TPID=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
kill -9 $TPID
sleep 5;
TSTAT=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
if [ -z $TSTAT ];then
echo -e "\033[32mtomcat stop success...\033[0m"
else
kill -9 $TSTAT
fi
rm -rf $TOM_PATH/temp/*
rm -rf $TOM_PATH/work/*
}
main () {
case $1 in
start)
tomcat_start;;
stop)
tomcat_stop;;
status)
tomcat_status;;
restart)
tomcat_stop && tomcat_start;;
*)
usage;
esac
}
main $1
执行脚本测试:
#!/bin/bash
#date 2016-06-17
#Author ouyang
#
usage () {
echo -e "\033[35mUsage: $0 [start|stop|status|restart]\033[0m"
}
tomcat_start () {
/usr/local/tomcat/bin/startup.sh
}
tomcat_status () {
STAT=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
if [ ! -z $STAT ];then
echo -e "\033[32mTomcat is Running...\033[0m"
else
echo -e "\033[33mTomcat is not Running...\033[0m"
fi
}
tomcat_stop () {
TOM_PATH=/usr/local/tomcat
TPID=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
kill -9 $TPID
sleep 5;
TSTAT=$(ps aux |grep java|grep tomcat|grep -v 'grep'|awk '{print $2}')
if [ -z $TSTAT ];then
echo -e "\033[32mtomcat stop success...\033[0m"
else
kill -9 $TSTAT
fi
rm -rf $TOM_PATH/temp/*
rm -rf $TOM_PATH/work/*
}
main () {
case $1 in
start)
tomcat_start;;
stop)
tomcat_stop;;
status)
tomcat_status;;
restart)
tomcat_stop && tomcat_start;;
*)
usage;
esac
}
main $1
执行脚本测试:
编辑回复