【发布时间】:2024-01-12 16:37:01
【问题描述】:
我有下面的 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。现在我该如何修改上面的脚本来停止/启动remote tomcat?
谢谢!
【问题讨论】:
-
不清楚你想要什么,从另一台机器启动tomcat的bash脚本?
-
morgano,我可以从我的机器上运行脚本。但是脚本应该启动/停止位于远程的tomcat。Tomcat不在我的机器上。
-
使用 ssh 会话?使用在远程机器上监听的守护进程?
-
morgano,我远程安装了tomcat。我需要编写一个脚本,它将从任何系统启动/停止远程 tomcat。我真的不知道该怎么做。我通过谷歌搜索找到了上面的脚本。我应该怎么做才能启动/停止远程tomcat?
标签: java linux shell unix tomcat