Can‘t get periodic shutdown to work (Cron)

Dear people,

i am failing for quite some moons to get a Cron Job setup that would shutdown my TrueNAS device every morning at 01:00.

I‘ve tried poweroff as well as midclt call system.shutdown and both are working as long as there is an active session it seems. I can execute them manually and even time them for the next minute and it will work.

But timing it for the night fails everytime. I‘ve tried with different users, root, admin etc. but it just doesn‘t work.

What am I doing wrong?

Thank you!

A few things.

Are you root in the cron job?
If yes, then you may need to run the command in a shell (sh) using &&. I’m on travel right now so i can’t lookup the specific command but I have to use it for Multi-Report due to security enhancements. And then I’d use the poweroff command.

Sorry I can’t be of more help right now.

3 Likes

I tried (and failed) to get my TrueNAS box to shutdown on a schedule using the GUI cron job interface. For some reason, I just couldn’t get it to work. It would proclaim it had completed successfully in the logs, but that was not true at all!

I solved the problem by manually adding a shutdown command to the crontab file using the system shell.

sudo nano /etc/crontab

Then add the following the the bottom of the file:

00 01   * * *   root    /usr/sbin/shutdown -h now

Please post a screenshot of exactly how you have midclt call system.shutdown configured in the cron section.

Thanks! I’ve set it up and report back, whether it’ll work tomorrow! Thanks so much!

1 Like

That’s probably going to work, but it won’t be persistent. I was asking for a screenshot of how you actually set it up because your post didn’t go into any detail making it difficult to pinpoint the cause.

A cron job defined in the GUI like this ought to do the job:

/usr/bin/midclt call system.shutdown "Cron shutdown"

A difference from running the command in an active shell is that your shell has the path setup, so you don’t need the absolute path when you do it manually. I also added a shutdown reason in quotation marks because I think the command still requires that.

Edit: Fixed quotation mark.

1 Like

It persists between reboots, but it probably won’t persist between os updates. If there’s a solution that uses the GUI cron job that would be much better. Have you tried that?

Ok, well I tried your suggestion and it didn’t work for me.
The only thing that works is manually adding it to the crontab file.

…this doesn’t work:

… this does work:

1 Like

Same experience here. The GUI version just doesn’t work.
Adding to the crontab file via shell has worked, but strangely my NAS has rebooted instantly instead of staying off :frowning:

AI said I should try -p instead of -h, so I’m gonna try
00 01 * * * root /usr/sbin/shutdown -p now
@neofusion my GUI-Setup for the cron job was exactly as substeeze has screenshotted above.

Yes, there’s a difference between -h (halt) and -p (poweroff). On my (very old Dell system) the -h does power it off completely, but maybe on newer hardware the -p is needed to totally shutdown.

I just entered the above GUI cronjob and it was successful. TrueNAS 25.10.1 tested just now

I did fix the double quotes on both sides of the reason.

/usr/bin/midclt call system.shutdown "Cron shutdown"

I’m also on 25.10.1 and just tried the GUI Cron again with your change of quotes, but still doesn’t work.
If I click the ‘run it now’ play arrow, yes, it will shutdown. But it will not shutdown on the schedule I set. Very strange.

Have you checked in the Audit Logs to see if there are any clues?

1 Like

FWIW this is my cronjob. Disabled r/n because I’ve actually needed the NAS running overnight for something.


I use systemctl poweroff. Don’t ask me why. This was setup over a year ago.

In my case, the system (sometimes) reboots and doesn’t power off. I suspect that’s because of my motherboard and UPS’ USB cable waking up the system and I’ve just been too lazy to go investigate.


Edit:

huh…well maybe it isn’t USB waking up the system…

1 Like

Ok. Just run the GUI cron again (scheduled for 12:55). In the Audit log, there is something that claims to have run, but it hasn’t shutdown…

and in the syslog I have this:

Mar 22 12:55:01 TrueNASBackup CRON[3859]: (root) CMD (PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" midclt call cronjob.run 6 true > /dev/null 2> /dev/null)
Mar 22 12:55:33 TrueNASBackup systemd[1]: Cannot find unit for notify message of PID 3864, ignoring.

I show two entries. One in Middleware and two? in System around the shutdown time. I was logged out of TrueNAS when mine did the Cron shutdown at 19:38 time


Yes, I get that too - but it doesn’t actually shutdown the machine…

going to give it another shot in 25mins…

Ok, so I set it for 16:23. All I see in the logs is a System entry for CRON. I am assuming this means the cron daemon has triggered on the schedule ok. But there’s nothing in the Middleware logs, so it seems the command has failed. This could be a permissions issue with user ‘root’ perhaps? I’m going to try poking around with the user credentials and see if I can solve this.

Having no luck with this. I can get it to work if I run it manually, but on the GUI cron, no joy.

One thing that is puzzling me, is in the audit logs, the path to the cron command is in upper case, rather than lower case - could this be the issue? Is it a bug?

Ok. I’m pretty sure this is a bug with my instance of Goldeneye.

I’ve tried setting up a GUI cron job on my other Fangtooth box and it works flawlessly.

Going to try updating the Goldeneye box from 25.10.1 to the latest.