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

Java Tomcat启动和停止使用shell脚本?,java,linux,shell,unix,tomcat,Java,Linux,Shell,Unix,Tomcat,我有下面的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 }

我有下面的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\u tomcat.sh
将是远程机器中的脚本,当然您需要远程机器上的有效用户名/密码,并且远程机器需要安装并运行sshd

不清楚您想要什么,从另一台机器启动tomcat的bash脚本?morgano,我可以从我的机器上运行脚本。但是脚本应该远程启动/停止位于中的tomcat。tomcat不在我的计算机中。是否使用ssh会话?使用远程机器上监听的守护进程?morgano,我远程安装了tomcat。我需要写一个脚本,从任何系统启动/停止远程tomcat。我真的不知道怎么做。我通过谷歌搜索找到了上面的脚本。如何启动/停止远程tomcat?morgano,ssh表示Putty?morgano,start_tomcat.sh脚本将不在远程计算机中。脚本将在我的本地计算机中,但tomcat实例正在远程计算机中运行。是的,如果您的本地计算机是Windows,您可以使用Putty,我在回答中使用的命令行仅适用于unix TerminalMorgo,start_tomcat.sh脚本将不在远程计算机中。脚本将在我的本地机器上,但tomcat实例正在远程机器上运行OK,试想一下,如果tomcat没有运行,因此没有在任何端口侦听以接收“start”命令,您将如何告诉tomcat在远程机器上启动?据我所知,你的本地机器是Windows,对吗?在这种情况下,您需要在windows的命令行中使用ssh客户端,然后需要创建使用该ssh客户端的*.bat或*.cmd脚本