Is there a specific menu for cronjobs with dietpi that I don’t know of? I checked in dietpi-services and cron is there but no editing of crons there.
So I did the regular way: sudo crontab -e
Added my 2 test cronjobs:
0 6 * * * /sbin/shutdown -r
5 6 * * * reboot
(Empty line at the end)
Then I restarted the cron service but it’s been 2 days and my PC never restarted. From what I saw so far, if there’s an integrated way to do something in DietPi, it always works better so I’m wondering if there’s a menu I missed.
There is dietpi-cron but it is used to adjust the running time of the /etc/cron.*/* . If you add a script in those folders it will be executed during the designated time.
For testing, I added this 32 9 * * * echo $(date) > /tmp/test
and it worked fine as the date was printed on the file at the given time.
Does that work for you?
Thanks for your answers guys, actually when looking at journalctl (I did not know cron info was in there), the cron seems to be working and not working at the same time, I changed the time of both operations for 11:15 and 11:17 and saw this:
# Note: To avoid infinite reboot loop, wait 70 seconds
# and touch a file in /etc so clock will be set
# properly to 06:06 on reboot before cron starts.
5 6 * * * sleep 70 && touch /etc/banner && reboot
Hey MichaIng, thanks you were right about the shutdown command!
Just out of curiosity I still tested with shutdown -r, the result was:
Failed to connect to bus: No such file or directory
And the result with reboot is
/bin/sh: 1: reboot: not found
Is it because the cron is ran as root and it should be as the user dietpi instead? Because I found this:
I’ll wait for an answer here before just dumping /usr/sbin/reboot, in case there is a more “proper” way of doing this (And also so I can mark the next post as the official solution for anyone ending up here from Google).