Why is crond treating my job as erroring? / How to prevent successful cron runs from being logged?

I'm trying to prevent syslog from logging an error message each time a successful once-a-minute cron job runs. I've followed the advice in this post:

and set my 'cronloglevel' to '9' so that only errors should be printed. However, I'm still seeing the following printed in my logs each time the job runs, which makes me think that crond is seeing my job as erroring:

Fri Dec 1 15:33:00 2023 cron.err crond[1992]: USER root pid 25046 cmd /usr/sbin/test.sh

Here are the contents of that script:

#!/bin/sh

uptime >> /tmp/uptime.log

And I verified it is producing output:

# tail /tmp/uptime.log 
 15:25:00 up 3 days, 18:50,  load average: 0.12, 0.19, 0.17
 15:26:00 up 3 days, 18:51,  load average: 0.10, 0.17, 0.17
 15:27:00 up 3 days, 18:52,  load average: 0.30, 0.22, 0.18
 15:28:00 up 3 days, 18:53,  load average: 0.10, 0.18, 0.17
 15:29:00 up 3 days, 18:54,  load average: 0.10, 0.16, 0.16
 15:30:00 up 3 days, 18:55,  load average: 0.11, 0.16, 0.16
 15:31:00 up 3 days, 18:56,  load average: 0.09, 0.14, 0.16
 15:32:00 up 3 days, 18:57,  load average: 0.31, 0.21, 0.18
 15:33:00 up 3 days, 18:58,  load average: 0.22, 0.21, 0.18
 15:34:00 up 3 days, 18:59,  load average: 0.23, 0.23, 0.19

The job is running successfully, but I can see from the log message that this is being logged as an error ("cron.err"). Is this because there is some indicator that crond requires to consider the job "successful" and I'm not providing it? If so, what does my script need to do? If not, is there any other way to prevent crond from treating my job as erroring and logging it as such?

I believe I've read something to that matter a while ago, it's a bug with built-in cron. I ended up switching to micrond because of that.

Ah, ok. I was hoping it was something like "your job needs to have a specific return/exit code" which would be each enough to change. But I can look into a replacement for the built-in crond.

Did you restart crond or make it read the new config settings?

From what I've read, the crond is a applet of busybox in OpenWrt and is stripped down a bit and has fewer features than the full modern crond does and one of the results is that crond logs everything as severity level err.

3 Likes

No, I didn't. My understanding has been that the 'cronloglevel' in /etc/config/system was applied to the system log daemon, not the cron daemon, so the restarts I did were on /etc/init.d/log and /etc/init.d/system. I will try /etc/init.d/cron for good measure, however.

That sort of makes sense, and makes me think I probably want to look at an alternative to busybox's crond.

Is there a full busybox with full cron to choose instead?

WELP. That fixed it. I guess that is a cron setting and not a logd setting. :man_shrugging: Thanks for the suggestion!

3 Likes

I'm not an expert. I see that there is an selinux version available in pkg busybox-selinux and the linked thread in post 1 mentions trying micrond .
A couple years ago I looked at https://www.busybox.net/ as a possible alternative but I did not try building it for OpenWrt. I might have read here on the forums that there are OpenWrt additions to deal with so it might work as an addition to the built-in busybox but not easily replace it without a bunch of added code.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.