linux - 在日志文件中报告状态 crontab 行 Linux RedHat

标签 linux shell sed redhat

我想知道如何提取 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/

相关文章:

c - 在内存中打开和加载文件的方法

linux - 在 Linux 中以特定时间间隔调用函数

linux - 将 Linux x86-64 程序集 hello world 程序与 ld 链接失败

linux - 如何获取 Linux 命令的完整路径名

linux - 使用 bash 脚本从文件中删除特定行

bash - 为什么 sed 在我的 bash 脚本中不起作用?

regex - 在输出中查找并替换为正则表达式

c - 如何从客户端调用 C 服务器中的函数

bash - Shell脚本运行命令创建多个进程

bash - 基于文件位置而不是当前工作目录的相对路径