大网数据广告活动
服务器运维问答

Reduce cron log level with systemd

· 52CE 我爱测

Googling for a solution, I only found articles telling me how to do it in old systems and not under a systemd maintained Linux, by changing the cron init-script adding -L parameter to the command line. I have a cron job that runs…

问题原文

原帖链接 · fdafgfdgfagfdagfdagfdagfdagfda · CC BY-SA 4.0

Googling for a solution, I only found articles telling me how to do it in old systems and not under a systemd maintained Linux, by changing the cron init-script adding -L parameter to the command line.

I have a cron job that runs every minute. It logs every start and additionall a pam_unix-entry for each session opened and closed for the user running cron. This is a lot of babbeling in the journald log. How can I set the log level in a systemd-environment, that I only get errors and fatalities documented?

Example messages:

CRON[4041958]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
CRON[4041958]: pam_unix(cron:session): session closed for user root

已采纳解答

原帖链接 · user9517 · CC BY-SA 3.0

Ok so I only have EL systems to hand but I asked a friend who as a Debian 8 system and the answer is broadly the same.

For Debian using cron (substitute crond for EL)

systemctl status cron 
systemctl status cron
cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled)
   Active: active (running) since Mon 2015-11-02 21:13:22 CET; 1 months 0 days ago
     Docs: man:cron(8)
 Main PID: 983 (cron)
   CGroup: /system.slice/cron.service
           983 /usr/sbin/cron -f

If you then look at the contents of /lib/systemd/system/cron.service

[Unit]
Description=Regular background program processing daemon
Documentation=man:cron(8)

[Service]
EnvironmentFile=-/etc/default/cron
ExecStart=/usr/sbin/cron -f $EXTRA_OPTS
IgnoreSIGPIPE=false
KillMode=process

[Install]
WantedBy=multi-user.target

You can see that it loads an environment file /etc/default/cron amd from that file it uses $EXTRA_OPTS

If your cron daemon supports it you can provide an option to change the logging verbosity there

EXTRA_OPTS="-L 0"

The man page for your distro's cron(d)(8) should tell you what logging options you have.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-12-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。