Help needed with cron jobs not running automatically

Joined
Sep 11, 2021
Messages
11
Update: see solution in 3rd post

I'm on TrueNAS-SCALE-23.10.0.1, but this issue has been with me for a while. I've set up a few cron jobs (in system settings/advanced), and while they run without problems when executed manually (triangle icon), they never run automatically.

One of my jobs runs "heavyscript backup" at 3 am (see attached image). After a manual run, I'm sent an e-mail with the output. It's all good as long as I run it manually, however, nothing happens at 3 am - no email, no backup made. On the other hand, replication tasks run on time and reports are sent, and I also get emails about other outstanding issues, so it's not an issue with the notification system or all cron jobs. Nextcloud cron jobs (configured by the Truecharts app) also run regularly (as far as they're present in journalctl), but my own cron jobs don't. And this isn't something that worked until one point and then broke, this cron job has never run by itself as far as I can tell.

I'd appreciate any advice on how to dig deeper to understand and fix the issue.

I've found some threads in these forums about cron jobs, but none of these seemed to focus on a similar issue.
 

Attachments

  • failing cron job.png
    failing cron job.png
    22.5 KB · Views: 111
Last edited:

Tony-1971

Contributor
Joined
Oct 1, 2016
Messages
147
Hello,
Try using
Code:
/usr/bin/bash

instead of
Code:
bash

Best Regards,
Antonio
 
Joined
Sep 11, 2021
Messages
11
Thank you for the suggestion, but this was not the issue. The /etc/cron.d/middlewared file includes /usr/bin in its path so "bash" is just as good as "/usr/bin/bash".

However, I was able to identify the cause. One of my cron jobs had the minute defined as 1/10 instead of */10 and this caused the following error (from journalctl -xe):

Code:
Dec 01 22:36:01 MainNAS cron[3313]: (*system*middlewared) RELOAD (/etc/cron.d/middlewared)
Dec 01 22:36:01 MainNAS cron[3313]: Error: bad minute; while reading /etc/cron.d/middlewared
Dec 01 22:36:01 MainNAS cron[3313]: (*system*middlewared) ERROR (Syntax error, this crontab file will be ignored)


The offending cron job:

Code:
1/10 * * * * root PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" midclt call cronjob.run 1 true > /dev/null 2> /dev/null


I've changed it to */10 and now it runs as expected.

However, while I'm not certain it's correct cron syntax or not, 1/10 is recognised as correct by the UI! It's telling me that 1/10 means every 10 minutes starting from 1. So, even though it was a mistake on my part, the UI didn't complain about it. I'm wondering if it's an oversight.
 
Joined
Sep 11, 2021
Messages
11
Now that all jobs are running, I'm having another issue with not being able to hide their output. One job that runs every 10 minutes has both stdout and stderr output hidden (both boxes checked) and I'm still getting an email every 10 minutes. Did I overlook another setting that overrides the ones in the job's configuration?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Just add >/dev/null 2>&1 to the end of your command.
 
Joined
Sep 11, 2021
Messages
11
Yes, that works, but did I misunderstand the purpose of the "hide output" checkboxes in the UI?

Patrick, would you let me know what you think about the above error with the cron job? Is 1/10 supposed to be OK or not? I'm aware this is very likely a minor issue, especially since a workaround is easy, but the discrepancy between the UI and system running the job might be worth a ticket.
 
Top