Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@noahbliss
Last active January 6, 2021 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahbliss/f338638d74b4e819181c8b7c00d20367 to your computer and use it in GitHub Desktop.
Save noahbliss/f338638d74b4e819181c8b7c00d20367 to your computer and use it in GitHub Desktop.
Backup and restore interfaces file and reboot system if not canceled.
#!/usr/bin/env bash
# Noah Bliss
# GPLv3 License
# Backup and restore interfaces file and reboot system if not canceled.
# This program will hang the terminal. I prefer it that way and use tmux in a split window.
file="/etc/network/interfaces"
backup="/etc/network/interfaces.safe"
echo "Backing up $file to $backup"
if ! cp "$file" "$backup"; then echo "Failed to backup"; exit 1; fi
# If we have inotifywait, use it.
if command -v inotifywait >/dev/null; then
echo "Using inotifywait to monitor file for changes..."
inotifywait -e modify "$file"
date=$(date)
echo "Now is $date"
echo "Sleeping for 2 minutes. I will restore the backup file and reboot the system if I am not canceled."
sleep 1m
echo "One minute left."
sleep 30
echo "30 seconds left."
sleep 20
echo "10 seconds left."
sleep 10
else
date=$(date)
echo "Now is $date"
echo "Sleeping for 5 minutes. I will restore the .safe file and reboot the system if I am not canceled."
sleep 4m
echo "One minute left."
sleep 30
echo "30 seconds left."
sleep 20
echo "10 seconds left."
sleep 10
fi
cp "$backup" "$file"
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment