1. 新建shell空脚本文件,如 /home/tr.sh,并设置权限
# chmod 750 /home/tr.sh
2. 设置文件形式:
# sed -e 's/^M//g' /home/tr.sh > /home/tr.sh
3. 编辑脚本
# vi /home/tr.sh
tomcat_home=/home/apache-tomcat-8.5.15
SHUTDOWN=$tomcat_home/bin/shutdown.sh
STARTTOMCAT=$tomcat_home/bin/startup.sh
echo "关闭$tomcat_home"
$SHUTDOWN
ps -ef |grep tomcat |grep $tomcat_home |grep -v 'grep'|awk '{print $2}' | xargs kill -9
#删除日志文件,如果你不先删除可以不要下面一行
#rm $tomcat_home/logs/* -rf
#删除tomcat的临时目录
rm $tomcat_home/work/* -rf
sleep 5
echo "启动$tomcat_home"
$STARTTOMCAT
#看启动日志
tail -f $tomcat_home/logs/catalina.out
4. 查看文件形式是否正确,如下则正确
# cat -A /home/tr.sh
tomcat_home=/home/apache-tomcat-8.5.15$ SHUTDOWN=$tomcat_home/bin/shutdown.sh$ STARTTOMCAT=$tomcat_home/bin/startup.sh$ echo "M-eM-^EM-3M-iM-^WM--$tomcat_home"$ $SHUTDOWN$ ps -ef |grep tomcat |grep $tomcat_home |grep -v 'grep'|awk '{print $2}' | xargs kill -9$ $ #M-eM-^HM- M-iM-^YM-$M-fM-^WM-%M-eM-?M-^WM-fM-^VM-^GM-dM-;M-6M-oM-<M-^LM-eM-&M-^BM-fM-^^M-^M-dM-=M- M-dM-8M-^MM-eM-^EM-^HM-eM-^HM- M-iM-^YM-$M-eM-^OM-/M-dM-;M-%M-dM-8M-^MM-hM-&M-^AM-dM-8M-^KM-iM-^]M-"M-dM-8M-^@M-hM-!M-^L$ #rm $tomcat_home/logs/* -rf$ #M-eM-^HM- M-iM-^YM-$tomcatM-gM-^ZM-^DM-dM-8M-4M-fM-^WM-6M-gM-^[M-.M-eM-=M-^U$ rm $tomcat_home/work/* -rf$ $ sleep 5$ echo "M-eM-^PM-/M-eM-^JM-($tomcat_home"$ $STARTTOMCAT$ #M-gM-^M-^KM-eM-^PM-/M-eM-^JM-(M-fM-^WM-%M-eM-?M-^W$ tail -f $tomcat_home/logs/catalina.out$
5. 完成上面的步骤即可使用shell脚本命令重启tomcat
# /home/tr.sh