Skip to content

Instantly share code, notes, and snippets.

@AurelienLavorel
Created August 20, 2015 20:21
Show Gist options
  • Save AurelienLavorel/15e778fd7a47d230704f to your computer and use it in GitHub Desktop.
Save AurelienLavorel/15e778fd7a47d230704f to your computer and use it in GitHub Desktop.
Add failover Debian
#!/bin/sh
display_usage() {
echo "This script must be run with super-user privileges."
echo -e "\nUsage:\n$0 ip [interface] \n"
echo -e "\nExample:\n$0 192.168.0.1 eth1 \n"
}
# if less than one argument supplied, display usage
if [ $# -le 0 ]
then
display_usage
exit 1
fi
# check whether user had supplied -h or --help . If yes display usage
if [[ ( $# == "--help") || $# == "-h" ]]
then
display_usage
exit 0
fi
# display usage if the script is not run as root user
if [[ $USER != "root" ]]; then
echo "This script must be run as root!"
exit 1
fi
FAILOVER_IP=$1
NET_DEV=$2
if [ $# -le 1 ]
then
NET_DEV="eth0"
fi
ALIAS_NUMBER=$(command grep -e "iface[ \t]*${NET_DEV}:" '/etc/network/interfaces' \
| command wc --lines)
command echo "auto ${NET_DEV}:${ALIAS_NUMBER}
iface ${NET_DEV}:${ALIAS_NUMBER} inet static
address ${FAILOVER_IP}
netmask 255.255.255.255
broadcast ${FAILOVER_IP}
" >> '/etc/network/interfaces'
command ifup ${NET_DEV}:${ALIAS_NUMBER}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment