我正在尝试使用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
答案 0 :(得分:1)
请按照以下步骤操作:
.sh
文件(即StartStopScript.sh)中的一个位置。export BASE
变量。prog
变量。 StartStopScript.sh start
启动服务器
StartStopScript.sh stop
停止服务器
StartStopScript.sh restart
重新启动服务器
StartStopScript.sh status
检查服务器状态