gpt4 book ai didi

java - Tomcat启动和停止使用shell脚本?

转载 作者:行者123 更新时间:2023-11-29 00:01:24 25 4
gpt4 key购买 nike

我有下面的 shell 脚本来停止/停止 tomcat。

#!/bin/bash

export BASE=/home/programs/jakarta-tomcat-5.0.28/bin
prog=jakarta-tomcat-5.0.28

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

现在上面的脚本适用于本地 tomcat。现在我如何修改上面的脚本来停止/启动远程 tomcat

谢谢!

最佳答案

您可以使用 ssh 在远程机器上执行本地脚本来启动/停止 Tomcat,因此如果您在 linux 终端中,您可以执行如下操作:

ssh username@remoteMachine /home/username/myScipts/start_tomcat.sh

其中 start_tomcat.sh 将是远程机器中的脚本,当然您需要远程机器上的有效用户名/密码,并且远程机器还需要安装 sshd 和运行

关于java - Tomcat启动和停止使用shell脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21724910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com