Cron jobs not running on schedule

Started by whatever, March 19, 2023, 09:25:22 PM

Previous topic - Next topic
Hi there,

I'm trying to set up a cron job that will run every minute. In the minutes field, I've tried */1, *, and listing out all the minutes in a comma-seperated list. It simply will not run every minute. Instead, it runs at 6 minutes intervals, like clockwork.

Any idea what I'm doing wrong?

Thanks

Hi, whatever,

Instead of letting people guess what you actually did by giving a description, why not give details/copypaste/screenshot of the actual cron line? :-P

Where did you configure it?

I think what you want is only */1 for the minute field, no list. Try https://cron.help/#*/1_*_*_*_* for an interactive explanation!

March 19, 2023, 11:18:55 PM #2 Last Edit: March 19, 2023, 11:22:50 PM by whatever
Hi wbk,

Thanks for the reply.

Here's the screenshot. The thing is, I understand how cron works. And my cron job should be running every minute but it runs every 6 minutes instead - that's what I don't get.

Any ideas as to why it runs every 6 minutes instead every minute?

Hi whatever,

Quote from: whatever on March 19, 2023, 11:18:55 PM
Here's the screenshot. The thing is, I understand how cron works. And my cron job should be running every minute but it runs every 6 minutes instead - that's what I don't get.

Any ideas as to why it runs every 6 minutes instead every minute?

I created your rule on my system and checked /etc/crontab to see if it got mangled in one way or another, but it is not added there.
Then there is /etc/cron.d/at , which executes /usr/sibexec/atrun every 5 minutes.

My first guess would be that GUI-configured cron does not end up in regular cron jobs, and that atrun runs the jobs from the GUI. I mostly speculate this, because that would match your observation of 6 minutes, which could be 5 minutes for atrun, + 1 minute for the GUI-configured interval.

The documentation does not make it clear to me where the configured jobs are saved and how they are executed, see https://docs.opnsense.org/manual/settingsmenu.html#cron

March 19, 2023, 11:52:20 PM #4 Last Edit: March 20, 2023, 09:06:37 PM by meyergru
Nope, it's not "at". Such jobs are added to /var/cron/tabs/nobody.

The specific outcome would be:

# Origin/Description: cron/Alias reload
*/1       *       *       *       *       /usr/local/sbin/configctl -d filter refresh_aliases

Different than some other cron jobs, this one seems to not suppress stdout, such that an email could be sent (although the output is not very informative, being a UUID). Maybe if the mail configuration is incorrect, this times out after 5 minutes, such that the next starts will be delayed until then?

The called command itself takes only a second on my box...
Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A

Thanks wbk, and meyergru for your responses.

@meyergru I didn't have Monit configured, so I have no email settings on my box.

Also checked in /var/cron/tabs/nobody. Cron job is listed correctly.

Has cron always acted this way in OPNsense? Feels like a bug...

How do you know that it runs only once in 6 minutes? I did not look into what it does here...
Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A

Firewall > Log Files > General

The job runs every 6 minutes on the dot.

March 20, 2023, 10:02:00 AM #8 Last Edit: March 20, 2023, 10:04:27 AM by meyergru
I am quite sure that you misinterpret that information. I have entries in there that concern "alias", but not the ones that are caused by that cron line. configctl only triggers actions in configd.

Generally speaking, the log output of such events may be split up to different log sections via syslog.

I do see log entries on my Graylog instance every minute like so:

2023-03-20 09:54:00.000 OPNsense.mgsoft
OPNsense.mgsoft /usr/sbin/cron[22546]: (nobody) CMD (/usr/local/sbin/configctl -d filter refresh_aliases)


This is log level 6, facility "clock":

{
  "gl2_accounted_message_size": 236,
  "level": 6,
  "gl2_remote_ip": "192.168.1.2",
  "gl2_remote_port": 26953,
  "streams": [
    "000000000000000000000001"
  ],
  "gl2_message_id": "01GVZ3KD27JWW7KNSG402PYWGJ",
  "source": "OPNsense.mgsoft",
  "message": "OPNsense.mgsoft /usr/sbin/cron[22546]: (nobody) CMD (/usr/local/sbin/configctl -d filter refresh_aliases)",
  "gl2_source_input": "616dd51a51faec33cacc467a",
  "facility_num": 9,
  "gl2_source_node": "817eaa81-ad8f-46fd-9e6b-ebcb2587dd1d",
  "_id": "c1935573-c6fc-11ed-9893-5254005211e2",
  "facility": "clock",
  "timestamp": "2023-03-20T08:54:00.000Z"
}


What you refer to is /var/log/firewall/*, I have very few entries there at all. So maybe what you are seeing is something different. What happens when you disable the cron line? Does anything change or do the events still occur every 6 minutes? Or try using */30 - do the events occur less often?

Oh, and about email: Obviously, the standard configuration does no email at all.

Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 770 up, Bufferbloat A

Thanks for looking into this @meyergru.

Turns out you're correct. Looking in System > Log Files > Backend and filtering with the term "alias", shows the job being run every minute, as it should.

I was just looking at the wrong logs. Non-issue.

Thanks again.

Cheers