Last active
August 29, 2015 14:02
-
-
Save tacitochaves/ac5a1ebdfd21c973dbfc to your computer and use it in GitHub Desktop.
redundant.sh
This file contains hidden or 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
| #!/bin/bash | |
| # | |
| # redundant.sh | |
| # | |
| # Este script tratará a redundância entre dois links de internet. | |
| # | |
| # Author: Tácito Chaves - 2013-08-04 | |
| # e-mail: chaves@tchaves.com.br | |
| # fone: (98) 8123-8153 / 8857-9777 | |
| # set -x | |
| DATA=$(date +%d/%m/%Y) | |
| HORA=`date +%R` | |
| DEFAULT=$(route -n | grep ^0.0.0.0 | awk '{print $2}') | |
| INT_DEFAULT=$(route -n | grep ^0.0.0.0 | awk '{print $8}') | |
| GW_PRINCIPAL=10.0.3.2 | |
| GW_SECUNDARIO=192.168.3.254 | |
| INT_PRINCIPAL=eth1 | |
| DESTINO=8.8.8.8 | |
| LOG=/var/log/link.log | |
| if [ "$DEFAULT" == "$GW_PRINCIPAL" -a "$INT_DEFAULT" == "$INT_PRINCIPAL" ]; then | |
| PING=$(ping -c3 $DESTINO | grep -Eo "[0-9]{1,3}% packet loss") | |
| if [ "$PING" = '100% packet loss' ]; then | |
| `route add default gw $GW_SECUNDARIO` | |
| `route del default gw $GW_PRINCIPAL` | |
| echo "LINK PRINCIPAL - DOWN $DATA $HORA" >> $LOG | |
| echo "LINK PRINCIPAL - DOWN $DATA $HORA" | mutt -s "Link de Internet" tacito.ma@hotmail.com | |
| else | |
| echo "LINK PRINCIPAL - OK $DATA $HORA" >> $LOG | |
| fi | |
| else | |
| `route add default gw $GW_PRINCIPAL` | |
| PING=$(ping -I $INT_PRINCIPAL -c3 $DESTINO | grep -Eo "[0-9]{1,3}% packet loss") | |
| if [ "$PING" = '0% packet loss' ]; then | |
| `route del default gw $GW_SECUNDARIO` | |
| echo "LINK PRINCIPAL VOLTOU $DATA $HORA" >> $LOG | |
| echo "LINK PRINCIPAL VOLTOU $DATA $HORA" | mutt -s "Link de Internet" tacito.ma@hotmail.com | |
| else | |
| `route del default gw $GW_PRINCIPAL` | |
| echo "LINK PRINCIPAL CONTINUA DOWN $DATA $HORA" >> $LOG | |
| echo "LINK PRINCIPAL CONTINUA DOWN $DATA $HORA" | mutt -s "Link de Internet" tacito.ma@hotmail.com | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment