OpenWrt Forum Archive

Topic: [HowTo] dead man switch - restore a working config using a cronjob

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

When playing around with network/firewall settings there is a good chance you lock yourself out of your router. Here is an instruction how I make sure to get a working config again if that happens.

1) install openwrt
2) ssh to router
3) cp -r /etc/config /etc/config.orig
4) vim /root/

rm -rf /etc/config.modified
mv /etc/config /etc/config.modified
cp -r /etc/config.orig /etc/config

5) chmod u+x /root/
6) vim /etc/crontabs/root

# m h dom mon dow command
59 22 * * * /root/

7) /etc/init.d/cron restart

and now you can change stuff in /etc/config and if you break something the system will reset itself to the initial config at 22:59 (10:59pm) of course the router has to be powered on for that to happen.

(Last edited by davewood on 31 Mar 2015, 15:01)

Please write this awesome tip as a WIKI recipe. There are already too many good posts that are lost here on the forums...

If you make some changes and are satisfied that they are working, remember to recopy the config to /etc/config.orig.
Otherwise you will constantly revert to your original setup every night at 22:59 wheher you want to or not.

That's one of the many advantages of configuring extroot. Mess something up and all you have to do is power down, remove the extroot device, mount is on a Linux PC and fix it. No waiting for a cron job to kick in.

(Last edited by vernonjvs on 18 Jan 2016, 07:00)

Great idea!

I think implementation could be improved tho. As is, this script would cause the reboot wherever needed or not each day at 22:59. Would be great to actually check if there're difference between the /etc/config and /etc/config.orig which would require the restore/reboot.

Also bear in mind that if you mess up the networking enough for the router to not be able to receive the time from ntp servers, the restore/reboot wouldn't happen at 22:59, it would happen almost 23 hours after you start the router. So maybe checking the uptime instead of the actual time would work better.

The discussion might have continued from here.