Is there an dietpi-cronjobs menu?

Hello again all,

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.

Thanks!

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?

Or have a look to the journalctl log around the timestamp the cron should be executed. Maybe you will have an indication why thinks are not working.

There is no DietPi specific dialogue to manage cron entries. It’s all Linux/Debian default/standard. Nothing special on this.

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:

So it looks like the cron is executed, but the reboot never actually occurs.

(Uptime of 26 min is because I rebooted manually before running the tests)

are you going to use the root crontab or a user crontab? Can you try to a collect the output on a logfile and use following crontab entry

0 6 * * * /sbin/shutdown -r > /tmp/log1.txt
5 6 * * * reboot > /tmp/log2.txt

Thanks again Joulinar,

I do run as root yes, as I saw a previous post from MichaIng where it was saying it should be root. But whatever user doesn’t matter if another user is better.

Tried logging, both log files are empty when looking at the content (and 0 bytes filesize)

Better not in /tmp :wink:

Also:

# 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

Thanks, but I don’t have a reboot loop issue however, my PC just doesn’t reboot at all

The “no MTA” log indicates that those two jobs produce some output. Please log STDERR as well:

reboot > /tmp/log.txt 2>&1

/tmp is okay: If no reboot was done, the file remains. If the file isn’t there, obviously a reboot was done :wink:.

The shutdown command without now argument requires dbus to work, so use reboot only.

1 Like

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:
image

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).

@MichaIng sound like this PATH suddenly changed where the PATH to /usr/sbin/ is missing for corn jobs.

@NaturalBornCamper simply use the full path /usr/sbin/reboot for the reboot command.

Strange, where is this coming from, didn’t face it on any of my DietPi systems (which are a lot). Probably a bad cron update or so? I’ll have a look.

Thanks guys!

In case you missed when I said so earlier, I’m running DietPi on a PC, not a RPi (f that’s useful info)

2 posts were split to a new topic: How to use crontab-ui on DietPi?

OK, thanks, I will switch to new post.

I already split the topic to a new post:

2 Likes