我想知道如何提取 crontab 的状态。
目前我有这些行,执行关闭:
定时任务
#* * * * * cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
#* * * * * sleep 15 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
#* * * * * sleep 30 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
#* * * * * sleep 45 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
希望根据这些行的 crontab 状态,在日志文件中报告 ON 或 OFF。
在这种情况下我必须报告“OFF”
相反:
定时任务
* * * * * cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
* * * * * sleep 15 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
* * * * * sleep 30 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
* * * * * sleep 45 && curl cd $HOME;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
在这种情况下我必须报告“ON”
他们可以帮我出主意吗?
谢谢
最佳答案
crontab -l | awk '{if($0~/^ *#/){ print "OFF: " $0 } else print "ON : " $0 }' \
> cronStatusReport.$(/bin/date +%Y%m%d.%H%M)
应该会产生您正在寻找的输出。
输出(来自减少的数据集)
OFF: #* * * * * cd /C/Users/Neil_2;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
OFF: #* * * * * sleep 15 && curl cd /C/Users/Neil_2;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
ON : * * * * * sleep 30 && curl cd /C/Users/Neil_2;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
ON : * * * * * sleep 45 && curl cd /C/Users/Neil_2;sh .bash_profile >/dev/null 2>&1;cd /home/gisdesa/GIS/DESA;. ./loader_DESA.sh
健康教育
关于linux - 在日志文件中报告状态 crontab 行 Linux RedHat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30199989/