我有 CentOS 7 并且正在尝试访问一个配置文件,它看起来有点像这样:
# Cron configuration options
# For quick reference, the currently available log levels are:
# 0 no logging (errors are logged regardless)
# 1 log start of jobs
# 2 log end of jobs
# 4 log jobs with exit status != 0
# 8 log the process identifier of child process (in all logs)
#
我的目标是禁用 cron 日志记录。
我试过用谷歌搜索这个,显然有些人有类似的文件/etc/default/cron
,/etc/rsyslog.d/50-Default.conf
但当我搜索它们时,这些文件都不存在。我确实有/etc/rsyslog.conf
并尝试使用cron.none.* /var/log/messages
(我也没有/var/log/syslog
)来禁用 cron 日志记录,但我仍然在远程服务器上获取 cron 日志。
如何停止 cron 日志(但不停止 cron 本身)?我所做的一切似乎都无法阻止他们。
答案1
CentOS/RHEL 7 使用亲信cron 的实施。您在那里显示的文件涉及维克西克罗恩,用于 Debian 等发行版。
[root@centos7 ~]# head -2 /usr/share/doc/cron*/README
17. January 2008 mmaslano (at) redhat (dot) com
Rename the fork on cronie. The source code could be found here:
[root@centos7 ~]#
root@debian:/# head -20 /usr/share/doc/cron*/README
#/* Copyright 1988,1990,1993 by Paul Vixie
# * All rights reserved
# *
# * Distribute freely, except: don't remove my name from the source or
# * documentation (don't take credit for my work), mark your changes (don't
# * get me blamed for your possible bugs), don't alter or remove this
# * notice. May be sold if buildable source is provided to buyer. No
# * warrantee of any kind, express or implied, is included with this
# * software; use at your own risk, responsibility for damages (if any) to
# * anyone resulting from the use of this software rests entirely with the
# * user.
# *
# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
# * I'll try to keep a version up to date. I can be reached as follows:
# * Paul Vixie <[email protected]> uunet!decwrl!vixie!paul
# */
Vixie Cron V3.0
December 27, 1993
[V2.2 was some time in 1992]
root@debian:/#
默认情况下,亲信将/var/log/cron
使用/etc/rsyslog.conf
下面的条目发送所有 cron 消息
[root@centos7 ~]# grep ^cron /etc/rsyslog.conf
cron.* /var/log/cron
[root@centos7 ~]#
要更改它们的写入位置,请修改文件并重新启动 rsyslog。无需重新启动 cron。
[root@centos7 ~]# sed -i 's!/var/log/cron!/var/log/bob!' /etc/rsyslog.conf
[root@centos7 ~]# grep ^cron /etc/rsyslog.conf
cron.* /var/log/bob
[root@centos7 ~]# systemctl restart rsyslog
[root@centos7 ~]# tail /var/log/bob
Jul 7 19:16:41 centos7 crontab[8581]: (root) LIST (root)
Jul 7 19:17:01 centos7 CROND[8587]: (root) CMD (/bin/touch /tmp/foo)
[root@centos7 ~]#
并由 @doneal24 指出要完全丢弃条目,根据您原来的问题,您将使用/etc/rsyslog.conf
如下所示的行
cron.* ~