Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 启动/停止tomcat服务器的shell脚本_Bash_Shell_Tomcat_Sh - Fatal编程技术网

Bash 启动/停止tomcat服务器的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

我正在尝试在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
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

请按照以下步骤操作:

  • 将提供的代码保存在一个位置的
    .sh
    文件(即StartStopScript.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