前言
总有一些场景我们需要让内存看起来很满,那还等啥,填满她!
1. 准备脚本
准备 restart.sh
脚本
#!/bin/bash
pid=(netstat -nlp|grep :9500|awk '{print7}'|awk -F "/" '{print 1}')
if [ -z "pid" ];then
#自己启动服务的脚本或命令
sh ./xxx.sh
echo $(date +"%Y-%m-%d %T")"__程序宕机,自动重启" >> /opt/zhgd/app/restart.log
fi
2. 定时执行脚本
crontab -e
#每5分钟检查执行一次
*/5 * * * * sh /home/restart.sh