cron 排除日期
cron
is a very useful tool and mechanism to schedule jobs in a Linux operating system. cron can run scripts, commands, binaries if set properly. But in some cases, there may be some misconfiguration or unexpected behavior. So we may not be sure whether cron runs as we want. We can check cron log in order to get more detail about the job. By the way, more details about cron can be learned from the following tutorials.
cron
是在Linux操作系统中调度作业的非常有用的工具和机制。 如果设置正确,cron可以运行脚本,命令,二进制文件。 但是在某些情况下,可能会有一些配置错误或意外行为。 因此,我们可能不确定cron是否按照我们的要求运行。 我们可以检查cron日志以获取有关作业的更多详细信息。 顺便说一下,可以从以下教程中了解有关cron的更多详细信息。
Linux Crontab Syntax and Examples
Linux Crontab Tutorial with Examples To Schedule Jobs
Cron日志路径(Cron Log Path)
cron
logs are stored in a general log file named syslog
. This file can be found most of the popular distributions like CentOS, RHEL, Debian, Ubuntu. syslog
file is located regular log directory /var/log/syslog
.
cron
日志存储在名为syslog
的常规日志文件中。 该文件可以在CentOS,RHEL,Debian,Ubuntu等大多数流行发行版中找到。 syslog
文件位于常规日志目录/var/log/syslog
。
$ cat /var/log/syslog
检查Cron日志行(Check Cron Log Lines)
As we can see in the previous example there are a lot of log lines which is produced by different Linux component. But we need to find cron logs. There is a to filter and check only cron log lines. Every cron log line contains the string CRON
. So we will filter lines containing CRON
with grep
command like below.
正如我们在前面的示例中看到的,有很多日志行是由不同Linux组件生成的。 但是我们需要找到cron日志。 有一个用于过滤和检查cron日志行。 每个cron日志行都包含字符串CRON
。 因此,我们将使用grep
命令过滤包含CRON
行,如下所示。
$ grep CRON /var/log/syslog
As we can see log lines provides following information.
如我们所见,日志行提供以下信息。
Date
provides when the log is created.Date
提供创建日志的时间。hostname
provides the hostname of the system.hostname
提供系统的主机名。root
the user account which is used to run cron job.root
用户用于运行cron作业的用户帐户。CMD
what type of thing is trying to run which is the command in this case.CMD
在这种情况下,要运行的是哪种类型的命令。- and the last part provides the command tried to run. 最后一部分提供了尝试运行的命令。
实时跟踪Cron日志(Follow Cron Logs In Real Time)
If we want to read the cron job logs in real-time we can use the tail command with -f option. This will read the log file and print it to the screen. But before printing, we will filter only CRON
lines with grep
command like below.
如果要实时读取cron作业日志,可以将tail命令与-f选项一起使用。 这将读取日志文件并将其打印到屏幕上。 但是在打印之前,我们将使用grep
命令仅过滤CRON
行,如下所示。
$ tail -f /var/log/syslog | grep CRON
翻译自: https://www.poftut.com/troubleshoot-and-check-cron-job-logs/
cron 排除日期