Auto shutdown cron job - FreeNAS-11.3-U4.1

Frank33

Cadet
Joined
Aug 18, 2020
Messages
7
Hi every1, cant find solution online. So got a cronjob, root user, command: poweroff, schedule: 0 18 * * *, I can run the cronjob manually and it works, but on schedule doesnt. how do you guys auto shutoff freenas pls?
 

Alecmascot

Guru
Joined
Mar 18, 2014
Messages
1,177
search for "cron shutdown"
 

Alecmascot

Guru
Joined
Mar 18, 2014
Messages
1,177
work on the basis that everything has been asked before
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Try to use an absolute path when running commands from cron. The search path may differ when running commands from the commandline.
Please show us the line of the /etc/crontab file, which was generated by FreeNAS from your cronjob.
 

Frank33

Cadet
Joined
Aug 18, 2020
Messages
7
Tx 4 reply
So I cat the file below:

# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: src/etc/crontab,v 1.33.2.1 2009/08/03 08:13:06 kensmith Exp $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#
#minute hour mday month wday who command
#
*/5 * * * * root /usr/libexec/atrun > /dev/null 2>&1
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11 * * * * operator /usr/libexec/save-entropy > /dev/null 2>&1
#
# Rotate log files only at midnight.
0 0 * * * root newsyslog > /dev/null 2>&1
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time. See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a > /dev/null 2>&1

0 * * * * root /usr/local/bin/python /usr/local/bin/mfistatus.py > /dev/null 2>&1

30 3 * * * root /usr/local/bin/python /usr/local/bin/midclt call dscache.refresh > /dev/null 2>&1
45 3 * * * root /usr/local/bin/midclt call config.backup >/dev/null 2>&1
0 3 * * * root find /tmp/ -iname "sessionid*" -ctime +1d -delete > /dev/null 2>&1
30 */5 * * * root /etc/ix.rc.d/ix-kinit renew > /dev/null 2>&1


45 3 * * * root /usr/local/bin/midclt call pool.scrub.run freenas-boot 7 > /dev/null 2>&1

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



0 14 * * sun root PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" midclt call pool.scrub.run Cloudpoolname 14 > /dev/null 2> /dev/null


15 4 * * * root /usr/local/bin/python /usr/local/www/freenasUI/tools/autosnap.py > /dev/null 2>&1

59 2 * * * root /usr/local/bin/midclt call update.download > /dev/null 2>&1

@weekly root /usr/local/sbin/update-smart-drivedb > /dev/null 2>&1

*Dont see my cronjob
Regards
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Okay. The behavior seems to have changed a little from 11.2 to 11.3.
The command is no longer directly in the crontab but is callied via the middleware client.
There should be a line of the midclt call cronjob.run at the time of your scheduled cronjob.

Sure you have the cronjob enabled?

And please, next time you if you paste files or command output put it in [code][/code] tags.
 

Frank33

Cadet
Joined
Aug 18, 2020
Messages
7
tx so much for your help Fredda, really appreciate it.
i upload a video on how i created cronjob to autoshutdown.
as you will see cronjob doesnt execute on its own, schedule,
but if i run manually it works
idk
not sure what to do re ur line
"There should be a line of the midclt call cronjob.run at the time of your scheduled cronjob"

regards

cron
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Check the date/time on your FreeNAS server. The clock seems off. In the cronjob description it says "next run: 17 hours".
Have you set up ntp servers for your NAS? System->NTP Servers.
 

Frank33

Cadet
Joined
Aug 18, 2020
Messages
7
Good eye there on the time.
I usually power through the install process, I fixed the time and still no scheduled cron job executed.
NTP servers? No I have not done that. Would have to figure that out.

I think this exercise might be beyond me, im a linux user for like 5 months or so, have a spare laptop as my 'cloud', samba share desktop linux, and thought to give freenas a go. But it seems too complicated for me for now.
Im gonna throw in the towel.
And thank you so much for your time.

Stay safe and take care
Regards.
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Good eye there on the time.
I usually power through the install process, I fixed the time and still no scheduled cron job executed.
That is strange, if it executes correctly pressing the "run now" button, it should also run correctly when scheduled.
What does the "next run:" info show in the cronjob details?
You could also uncheck the "[ ] Hide Standard Output" checkbox on the cronjob setting.
Also use an absolute path for the command.
NTP servers? No I have not done that. Would have to figure that out.
As I said in the GUI: System->NTP Servers. Also, read the fine manuals chapter on NTP.
 

Frank33

Cadet
Joined
Aug 18, 2020
Messages
7
So good news.
And tx 4 not giving up, like I had.

So after unchecking "[ ] Hide Standard Output" checkbox, it triggered and worked.
Then I re checked it and it worked.
And I paid close attention to "next run" info.

Im gonna guess the timezone was probably what made it work. Maybe the server just needed more time to sync idk

In any case, I have successfully scheduled a poweroff at night

Didnt use absolute path, and still havent looked into NTP servers.

Looks like my freenas adventure continues.
Next adventure will be setup syncthing and maybe clamav.

Tx again, really appreciate it, if it wasnt for you, I would of given up.

Big hugs from me.
Take care, stay safe in this time.
Regards
 

Yorick

Wizard
Joined
Nov 4, 2018
Messages
1,912
If you don’t want to look deeply into ntp servers, just use pool.ntp.org, it’ll find one close to you. There are all kinds of nuances about time and why not to do what I suggest in an Enterprise, but for home use, completely adequate.
You want all your infrastructure devices, servers and clients to get time from NTP. Windows has something similar already built in, and Linux client may as well, not sure on that.

Good for you for sticking with it!
 

Fredda

Guru
Joined
Jul 9, 2019
Messages
608
Tx again, really appreciate it, if it wasnt for you, I would of given up.
You're welcome. Glad everything worked out. As Yorick pointed out, NTP is no rocket science.
You might want to use the same ntp-server your Linux installation uses, so assuming your Linux uses systemd you'll see the used ntp-server by typing systemctl status systemd-timesyncd and checking the status line.
 
Top