Crontab : 有没有开始和结束时间的日志?

Céd*_*ard 4 linux time logging cron

我的 linux 服务器上有很多用于我们的应用程序的 crontask。但是我找不到任何方法来知道任务何时结束以及运行多长时间。我必须添加一个像时间这样的软命令来记录这个吗?有没有办法配置 cron 来做到这一点?例如,我在 /etc/cron.daily 中有一个脚本需要太多时间,但我不知道是哪一个!

问候,
塞德里克

Ale*_*huk 7

man cron

你应该看到类似的东西

-L loglevel
               Sets the loglevel for cron. The standard logging level (1) will
               log  the start of all the cron jobs. A higher loglevel (2) will
               cause cron to log also the end of all cronjobs,  which  can  be
               useful  to  audit  the  behaviour of tasks run by cron. Logging
               will be disabled if the loglevel is set to zero (0).
Run Code Online (Sandbox Code Playgroud)

要使用该选项,您可以查看 /etc/default/cron

至少在 Debian 中它有这样的评论:

# Extra options for cron, see cron(8)
# For example, set a higher log level to audit cron's work
# EXTRA_OPTS="-L 2"
Run Code Online (Sandbox Code Playgroud)

更改配置文件后,您需要重新启动 Cron:

/etc/init.d/cron restart
Run Code Online (Sandbox Code Playgroud)