# 定时巡检 并保证任务一直运行 的作用
#!/bin/bash
# crontab定时
# */10 * * * * sh /data01/public_industry_address_parse/bin/monitor.sh
#根据项目部署修改
day=`date +'%Y%m%d'`
base_path="/data01/public_industry_address_parse"
monitor_log_file="${base_path}/logs/monitor_${day}.log"
parse_log_file="${base_path}/logs/parse_${day}.log"
if [ ${monitor_log_file} ];then
touch ${monitor_log_file}
fi
if [ ${parse_log_file} ];then
touch ${parse_log_file}
fi
datetime=`date +'%Y-%m-%d %H:%M:%S'`
echo "${datetime} 开始定时执行monitor脚本检查" >> ${monitor_log_file}
PARSEPID=`ps aux | grep 'main.py' | grep -v grep | wc -l` ##### 更改点
if [ ${PARSEPID} -gt 0 ];then
echo "地址解析进程正常" >> ${monitor_log_file}
else
echo "地址解析已停止,重新启动解析..." >> ${monitor_log_file}
nohup /data01/anaconda3/bin/python ${base_path}/main.py >> ${parse_log_file} 2>&1 &
if [ $? -eq 0 ];then
echo "重启解析成功完成." >> ${monitor_log_file}
else
echo "重启解析任务失败!" >> ${monitor_log_file}
fi
fi
# 重启任务 确保先将之前任务kill的作用
#!/bin/bash
# sh /mnt/disk1/exe_dir/hhy_remote/hhy_pro/linux_shell/start_main.sh
ops=$(ps -ef| grep -i hhy_0_event_fuse | grep -v grep |awk '{print $2}') #### 更改点 hhy_0_event_fuse
while [ $ops ]
do
kill -9 $ops
ops=$(ps -ef| grep -i hhy_0_event_fuse | grep -v grep |awk '{print $2}')
echo $ops+aa >>ttt.log
#sleep 2
done
echo $ops_new +bb
while [ ! $ops_new ]
do
sleep 3
cd /mnt/disk1/exe_dir/hhy_remote/hhy_pro/
nohup /mnt/disk1/exe_dir/python20220827/bin/python3.7 /mnt/disk1/exe_dir/hhy_remote/hhy_pro/hhy_0_event_fuse0__out.py >/mnt/disk1/exe_dir/hhy_remote/log/hhy_0_event_fuse.log 2>&1 &
echo 'restart process'
echo ccc >>ttt.log
sleep 5
ops_new=$(ps -ef| grep -i hhy_0_event_fuse | grep -v grep |awk '{print $2}')
echo ops_new +$ops_new
done
echo 'finish !!!!!!'
#
#syntax error: unexpected end of file 处理
#:set ff ----------------------# 在vim中查看文件的系统格式
#:set fileformat=unix---或 :set ff=unix------ # 在vim中将系统文件格式改为unix