Cron reboot loop

hello, I testing simple cron reboot job on my 1043 and I always get a reboot loop...

"30 8 * * * reboot" and "30 8 * * * sleep 70 && reboot"

what I doing wrong ? :slight_smile: thx

1 Like

I have experienced the same issue. If there's a reboot command in cron, it boot loops.

You have forgotten the essential piece of advice in the wiki:

touch /etc/banner after the 70 seconds sleep

https://wiki.openwrt.org/doc/howto/cron

30 4 * * * sleep 70 && touch /etc/banner && reboot

That action is needed to ensure that the clock after the boot starts from a moment after the cron schedule. There is no real-time clock. It does not matter, which file in /etc gets touched, but some file needs to get a new timestamp.

The explanation in the wiki is pretty clear. I have originally written it in the Openwrt forum, although that message seems to have been lost...

In the boot process the clock is initially set by sysfixtime to the most recent timestamp of any file found in /etc. The most recent file is possibly a status file or config file, modified maybe 30 seconds before the reboot initiated by cron. So, in the boot process the clock gets set backwards a few seconds to that file's timestamp. Then cron starts and notices a few seconds later that the required boot moment has again arrived and reboots again… (At the end of the boot process ntpd starts, and it may also take a while before ntpd gets and sets the correct time, so cron may start the reboot in between.)

One solution for cron is to use a delay and touch a file in /etc before reboot:
30 4 * * * sleep 70 && touch /etc/banner && reboot

NOTE:
the advice above has been written before NAND flashes got common. On new routers with NAND flash, a "sync" command is maybe needed just before reboot to ensure that the file time stamp actually gets written into the flash. (I have no evidence on that, but just a hunch in case the advice does not work. 1043 of OP is old NOR flash rtouer, so this has no relevance for that)

2 Likes

yes, thanks I found this command too, but not test it (amateurish)... so there is no change with newer versions of openwrt in this

ps. for schedule up and down wifi is still optimal this command?
"* 22 * * * ifconfig wlan0 down" and "* 8 * * * ifconfig wlan0 up"
thx

Has your old router got a hardware real-time clock?
If no, then there is no improvement on the cron & reboot advice above. The underlying core reason is still that most routers have no real clock information that survives a reboot, so the approach of using a recent file in /etc is the best approximation of the last known time (before ntp has fetched the correct time from internet).

There is actually improvement from 2016 for routers with a real-time clock (e.g. x86 based ones)...

https://git.openwrt.org/?p=openwrt/openwrt.git;a=commitdiff;h=e2fd1adaf57800bb2a6e20bd59a02e76eb6d7f89