#!/bin/bash
DATE=`date +%Y-%m-%d-%H-%M-%S`
echo "当前时间是:$DATE"
# 根据端口号查找进程
PID=`/usr/sbin/lsof -i:9002 |/usr/bin/awk 'NR==2{print $2}'`
echo "杀死当前Bootstrap进程pid:$PID"
kill -9 $PID
# 根据实际情况修改路径
echo "启动tomcat进程"
/usr/bin/bash /usr/java/apache-tomcat-9.0.20/bin/startup.sh
echo "等待20秒"
sleep 20
PID=`/usr/sbin/lsof -i:9002 |/usr/bin/awk 'NR==2{print $2}'`
echo "启动tomcat进程后的pid是:$PID"
echo "========================================================="
# crontab -l
# 每天凌晨四点重启一次后台服务
# 0 4 * * * /root/definite_time_restart.sh >> /var/log/reboot_time.log 2>&1
本文摘自 :https://blog.51cto.com/u