Sending email when a cron job runs?

MrChips

Cadet
Joined
Aug 31, 2013
Messages
8
I have configured a cron job through the admin GUI, and it runs fine and I can see the log output from it in the "history" table. Yay!

But!

Is there a way to configure SCALE to send me an email for cron jobs the same way it does for other system events?

Things that I've tried:
  • I have looked through this forum and found nothing on this specific topic. (Maybe I'm just blind/dense/etc? <--- Very real possibility!)
  • I have looked in the various categories for alerts settings, and I do not see an entry for cron jobs there.
  • I have "unset" the "Hide Standard Output" setting on the cron job.
  • I have "unset" the "Hide Standard Error" setting on the cron job.
Note: Those last two I did because the help bubbles in the GUI for standard output/error say "...When unset, any standard output is mailed to the user account cron used to run the command."

Thanks for any help you can provide!!!
 
Joined
Oct 22, 2019
Messages
3,641
Are these cron jobs being run as the root user?
 
Joined
Oct 22, 2019
Messages
3,641
I thought maybe you weren't. :wink: And thus, as a user without an email address configured.

As long as you have outgoing emails configured, have an email address for the root user, and other jobs successfully send emails, it might be because the cron jobs don't have any output to send?

I'm on Core, so it's hard to test it out. My own custom cron jobs send emails upon completion.

EDIT: If you you want to test out the above hypothesis, just add this line somewhere in your script/command for the Cron Task:
echo "all done"

Now see if it sends an email after completion.
 
Last edited:

MrChips

Cadet
Joined
Aug 31, 2013
Messages
8
So I found my problem. It's a "mea culpa"...

I just went back and did a thorough review of all my settings, and it turns out the email address I had set on my root user was misspelled. That's all. Nothing more than my horrific typing to blame!

*** Instruction time ***

For those that may see this thread in the future, here's the checklist for setting up a cron job in TrueNas SCALE and having its output emailed to you:

1. Use the email settings (bell/alerts icon -> gear icon -> email) to set up your basic mail sending capability via SMTP or Gmail. Be sure to test it to ensure it is actually sending emails.

2. For the user that will be running your cron job, ensure they have an email address in their user credentials entry (credentials -> local users -> {username} -> edit -> email). Note: I have only tested as root user, so your success may vary with other users. Also, double-check to make sure you spelled the address correctly. Don't be a dufus like me. :rolleyes:

3. Use the cron job settings (system settings -> advanced -> cron job) to set up your cron job. Set the "Run as User" to the user you configured an email for in step 2 above. Unset the "Hide standard output/error" checkboxes. This will guarantee that the job-log details are sent to the job user via email.

That should do it.
 
Last edited:
Joined
Oct 29, 2023
Messages
1
Thank you MrChips! Over a decade after you posted this, I found it and got this setup on Truenas SCALE today!
 
Top