Bash 启动/停止tomcat服务器的shell脚本
我正在尝试在linux服务器上使用shell脚本停止和启动tomcat。 下面是我从互联网上复制的shell脚本,但它不起作用。我对shell脚本是新手。 谁能帮我一下吗。提前谢谢Bash 启动/停止tomcat服务器的shell脚本,bash,shell,tomcat,sh,Bash,Shell,Tomcat,Sh,我正在尝试在linux服务器上使用shell脚本停止和启动tomcat。 下面是我从互联网上复制的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
#!/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
请按照以下步骤操作:
- 将提供的代码保存在一个位置的
文件(即StartStopScript.sh)中.sh
- 使用tomcat bin位置更新导出基变量
- 使用tomcat版本更新
变量prog
- 重要提示:使用参数eg运行脚本
StartStopScript.sh start
启动服务器
StartStopScript.sh stop
停止服务器
StartStopScript.sh restart
重新启动服务器
StartStopScript.sh status
检查服务器状态出现了什么错误?@RushiDaxini运行shell脚本后没有错误,打印此用法:tomcat start | stop | restart | status