Skip to content

Use cron to revert changes

anderpups edited this page Oct 17, 2023 · 3 revisions

You can use cron to revert changes that could possibly break the network.

This is useful for hosts that you don't have physical access to.

  1. Login to the host via ssh.

  2. Make a copy of the file you are about to change

     sudo cp /etc/systemd/network/04-eth0.network /etc/systemd/network/04-eth0.network.old
  3. Create a cronjob at minute 0 and minute 30 of every hour that will revert the file and reboot. Adjust the times as needed. You can remove the reboot command to make sure the file will actually be reverted prior to making any permanent changes. Type sudo crontabe -e to open root's crontab. Enter the following:

    # Revert changes
    0,30 * * * * /usr/bin/cp /etc/systemd/network/04-eth0.network.old /etc/systemd/network/04-eth0.network; sudo reboot
  4. Make your changes and restart networking or reboot. If your changes break networking,the cronjob will run, revert the changes and reboot the system. If your change is successful, remove the cronjob

Clone this wiki locally