Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.