Last active
January 6, 2021 20:08
-
-
Save noahbliss/f338638d74b4e819181c8b7c00d20367 to your computer and use it in GitHub Desktop.
Backup and restore interfaces file and reboot system if not canceled.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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