Last active
October 15, 2017 15:50
-
-
Save tschuxxi/b9bab1b10dc869bb52c09b92be5ae013 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
run=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper | |
# NextHop: Put here, eg. "4.1.1.2" "8.8.8.8" | |
Nexthop=( "HostA" "HostB" ) | |
# Number of Pings | |
Count=4 | |
# Source Interface, eg. eth0.100/ eth1 | |
Inf=eth1 | |
#Get the current VRRP priority | |
Prio=$(cat /etc/keepalived/keepalived.conf|grep priority|cut -d ' ' -f 2|awk 'NR>1{print $1}') | |
# Function: Commands to set the priority back | |
function SetPrioUp() { | |
$run begin | |
# Uncomment and adjust | |
#$run set interfaces ethernet eth0 vrrp vrrp-group 1 priority 110 | |
#$run set interfaces ethernet eth0 vif 102 vrrp vrrp-group 102 priority 110 | |
$run commit | |
# $run save | |
$run end | |
} | |
# Function: Commands to set the VRRP priority lower | |
function SetPrioDown() { | |
$run begin | |
# Uncomment and adjust | |
#$run set interfaces ethernet eth0 vrrp vrrp-group 1 priority 80 | |
#$run set interfaces ethernet eth0 vif 102 vrrp vrrp-group 102 priority 80 | |
$run commit | |
#$run save | |
$run end | |
} | |
# Function: Change the Priority if | |
function SetPrioUp { | |
# Check current prio and set up if necessary | |
if [ "$Prio" -ne 110 ] ; then | |
echo "setting prio up" | |
SetPrioUp | |
fi | |
} | |
function SetPrioDown { | |
# Check current prio and set down if necessary | |
if [ "$Prio" -ne 80 ] ; then | |
echo "setting prio down" | |
SetPrioDown | |
fi | |
} | |
# Ping test the $Nexthop | |
for i in "${Nexthop[@]}" | |
do | |
/bin/ping -c $Count -I $Inf $i > /dev/null | |
if [ $? -ne 0 ] ; then | |
# Set down or keep Priority | |
SetPrioDown; break | |
fi | |
done | |
# Set higher or keep Priority | |
SetPrioUp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment