通过 syslog 记录 atd 消息

通过 syslog 记录 atd 消息

我正在运行 CentOS 5.3,并希望记录来自“at”守护进程的所有消息。我的 syslog.conf 包含以下条目:

cron.* /var/log/cron

我假设 syslog 中的 cron 行指的是“cron、anacron、at 和 batch”的整个系列。但是,虽然 cron 和 anacron 操作似乎会被记录,但“at”操作不会被记录。如何记录 atd 操作?

感谢您的关注

(已添加)我想添加我的 syslog.conf 的内容以防出现错误:

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                         /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none        /var/log/messages

# The authpriv file has restricted access.
authpriv.*                      /var/log/secure

# Log all the mail messages in one place.
mail.*                          -/var/log/maillog


# Log cron stuff
cron.*                          /var/log/cron

# Everybody gets emergency messages
*.emerg                         *

# Save news errors of level crit and higher in a special file.
uucp,news.crit                      /var/log/spooler

# Save boot messages also to boot.log
local7.*                        /var/log/boot.log

答案1

通过查看“at”程序的源代码(来自 CentOS 5.3 源代码存储库), 看起来它确实记录到了 syslog 中,但只记录了与 at 守护进程本身有关的致命错误(例如,如果您尝试同时运行 2 个 at 守护进程)。

但是,进程执行、产生的返回代码和标准错误/输出根本不会记录到 syslog 中。即使打开调试(需要重新编译),日志消息也不是很有帮助(对于最终用户而言),并且会写出类似以下内容的内容:

atd[24116]: pid 24121 exited with status 0.

这对您识别哪个命令是由哪个用户运行的或者它的标准输出/错误是什么没有太大帮助。

亚德如果命令失败或在其标准输出/错误中产生任何内容,则向请求该命令的用户发送电子邮件通知。但对于成功而没有任何输出的命令,不会发送任何邮件。您可以使用 -m 标志更改这一点。

在(1)

-m 当作业完成时即使没有输出也向用户发送邮件。

答案2

对于这种情况,我将使用包装器来包装记录到 syslog 的命令。例如:

#!/bin/bash
logger -i -t mycmd Starting
/bin/somecommand
logger -i -t mycmd Completed
exit 0

然后从 cron、at 等,我将调用包装器脚本。

我知道这只是一种变通方法而不是解决方案,但它确实完成了工作。

答案3

/var/log/secure(RHEL)

atd 通过 PAM 记录日志,请检查您的 syslog.conf 以查明 pam 记录到哪里。

答案4

根据atd(8),它已经记录到系统日志,您只需要确保您没有任何错误的系统日志规则。

也许可以先在这里发布您的syslog.conf文件。

还请注意,atd就指定特定的日志设施而言,这是不可配置的,但这应该不是问题,您只需确保您的系统日志配置正确即可。

相关内容