Skip to content

Instantly share code, notes, and snippets.

@tschuxxi
Last active October 15, 2017 15:50
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 tschuxxi/b9bab1b10dc869bb52c09b92be5ae013 to your computer and use it in GitHub Desktop.
Save tschuxxi/b9bab1b10dc869bb52c09b92be5ae013 to your computer and use it in GitHub Desktop.
#!/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