Shell脚本启动/停止tomcat服务器

拉詹

我试图在Linux服务器上使用Shell脚本停止和启动tomcat。下面是我从Internet复制的shell脚本,但是它不起作用。我是Shell脚本新手。请任何人能帮助我。提前致谢。

#!/bin/bash

export BASE=/opt/tomcat/apache-tomcat-8.5.47/bin
prog=apache-tomcat-8.5.47

stat() {
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat is running.
else
echo Tomcat is not running.
fi
}

case "$1" in
start)

if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
echo Tomcat seems to be running. Use the restart option.
else
$BASE/startup.sh 2>&1 > /dev/null
fi
stat
;;
stop)
$BASE/shutdown.sh 2>&1 > /dev/null
if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
stat
;;
restart)

if [ `ps auxwwww|grep $prog|grep -v grep|wc -l` -gt 0 ]
then
for pid in `ps auxwww|grep $prog|grep -v grep|tr -s ' '|cut -d ' ' -f2`
do
kill -9 $pid 2>&1 > /dev/null
done
fi
$BASE/startup.sh 2>&1 > /dev/null
stat
;;
status)
stat
;;
*)
echo "Usage: tomcat start|stop|restart|status"
esac
Rushi Daxini

请按照以下步骤操作:

  • 将提供的代码保存在.sh文件(即StartStopScript.sh)中的一个位置。
  • export BASE使用tomcat bin位置更新变量。
  • prog使用tomcat版本更新变量。
  • 重要信息:使用参数eg运行脚本。

StartStopScript.sh start 启动服务器

StartStopScript.sh stop 停止服务器

StartStopScript.sh restart 重新启动服务器

StartStopScript.sh status 检查服务器状态

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章