Skip to content

Instantly share code, notes, and snippets.

@robotamer
Created December 15, 2011 03:57
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 robotamer/1479769 to your computer and use it in GitHub Desktop.
Save robotamer/1479769 to your computer and use it in GitHub Desktop.
"network_Safety_Restart.sh start" Will move /etc/network/interfaces.org to /etc/network/interfaces and restart the server after a given time. You can stop the script by issuing a "network_Safety_Restart.sh stop"
#! /bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin
. /lib/lsb/init-functions
export FILE=/etc/network/interfaces
case "$1" in
start)
SLEEPFOR=1200
WAITFOR=`expr ${SLEEPFOR} / 10`
while [ $SLEEPFOR -gt 0 ]; do
CALC="$SLEEPFOR seconds"
if [ $SLEEPFOR -gt "120" ]; then
CALC=`expr $SLEEPFOR / 60`
CALC="$CALC minutes"
fi
log_action_msg "WARNING: Will in $CALC rename ${FILE} and then restart"
sleep $WAITFOR
SLEEPFOR=`expr ${SLEEPFOR} - ${WAITFOR}`
echo $(pidof bash $0)
done
log_action_msg "Restarting NOW"
SUFFIX=$(date +%s)
cp ${FILE} ${FILE}.${SUFFIX}
sleep 1
cp ${FILE}.org ${FILE}
sleep 1
reboot -d -f -i
;;
stop)
log_action_msg "Terminating restart script"
PIDS=$(pidof bash $0)
for mypid in $PIDS; do
kill $mypid > /dev/null 2> /dev/null &
done
log_action_msg "Terminated restart script"
exit 0
;;
remove)
update-rc.d $0 remove
exit 0
;;
*)
echo "Usage: $0 start|stop|remove" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment