Skip to content

Instantly share code, notes, and snippets.

@agustik
Last active March 12, 2018 23:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save agustik/282abc3faf8f17ce3d41 to your computer and use it in GitHub Desktop.
Save agustik/282abc3faf8f17ce3d41 to your computer and use it in GitHub Desktop.
simple keepalived status script for 2 interfaces
#!/bin/bash
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";
;;
down)
service keepalived stop
;;
up)
service keepalived start
;;
*)
echo $"Usage: $0 {status|down|up}"
esac
@AysadKozanoglu
Copy link

thanks bro.. useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment