Skip to content

Instantly share code, notes, and snippets.

@AysadKozanoglu
Forked from agustik/vrrp
Last active March 12, 2018 23:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AysadKozanoglu/a0aa393e075802581646bcda4901646c to your computer and use it in GitHub Desktop.
simple keepalived status script for 2 interfaces
#!/bin/bash
# for Debian Jessie
configfile=/etc/keepalived/keepalived.conf
content=$(egrep '(vrrp_instance|interface|virtual_ipaddress)' -A1 $configfile | egrep -v "(\-\-|track_|virtual_)" | grep -A6 vrrp_);
#echo "$content";
instance_1=$(echo "$content" | grep "VI_1" -A4);
instance_2=$(echo "$content" | grep "VI_2" -A4);
if_1=$(echo "$instance_1" | grep "interface" | awk '{print $2}');
if_2=$(echo "$instance_2" | grep "interface" | awk '{print $2}');
state_1=$(echo "$instance_1" | grep "state" | awk '{print $2}');
state_2=$(echo "$instance_2" | grep "state" | awk '{print $2}');
vip_1=$(echo "$instance_1" | grep "dev" | awk '{print $1}');
vip_2=$(echo "$instance_2" | grep "dev" | awk '{print $1}');
case "$1" in
status)
service keepalived status
echo "------------------------------"
ips=$(ip addr show | grep "scope global secondary" | awk '{print $2}');
for ip in $ips ; do
echo "MASTER FOR:" $ip;
done;
echo "------------------------------"
echo "CONFIGURED: $if_1 $state_1 $vip_1";
echo "CONFIGURED: $if_2 $state_2 $vip_2";
;;
stop)
systemctl stop keepalived.service
;;
start)
systemctl start keepalived.service
;;
*)
echo $"Usage: $0 {status|stop|start}"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment