监控文件是否更新
shell脚本:
#! /bin/sh
date=$(date +%Y-%m-%d-%H:%M)
file_path=/root/airflow/scheduler.log
check_time=120
file_old_stat="`stat ${file_path}|grep Size`"
sleep ${check_time}
file_new_stat="`stat ${file_path}|grep Size`"
if [[ `echo ${file_old_stat}` == `echo ${file_new_stat}` ]]; then
. /data/venv/bin/activate && supervisorctl restart airflow_scheduler
echo "#${date},scheduler service restarted" >>/tmp/test/scheduler_hung.log
fi
定时任务:
*/2 * * * * /bin/sh /hongfeng/script/monitor_scheduler.sh >/dev/null 2>&1
python脚本:
# -*- coding: UTF-8 -*-
import os
import time
file='/root/airflow/scheduler.log'
atime=os.path.getatime(file) #输出最近访问时间1318921018.0
ctime=os.path.getctime(file) #输出文件创建时间
mtime=os.path.getmtime(file) #输出最近修改时间
ntime=time.time()
timed=ntime-mtime
timef="notime:%s, mtime:%s, timed:%d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ntime)),time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ctime)), timed)
print(timef)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步