Hi,
I am struggling with bash script. The purpose of script is to check whether or not virtual IP (keepalived) is up or not. If it is, then check for rest of external IP addresses configured in /etc/network/interfaces and then bring it up. If virtual IP is down, then check the same, but this time bring down additional IPs if they are still up. Now I need to add another condition: If virtual IP is up, and additional external IP addresses too, then do nothing. What I've done so far is:
Code:
IFACE='eth0'
VIP='1.2.3.4'
IFACES_FILE='/etc/network/interfaces'
STATUS=$( ip address show "$IFACE" | grep -o "$VIP" )
if [ ! -z "$STATUS" ]; then
ip_addresses=( $( grep -o 'up ip addr add [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' "$IFACES_FILE" | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' ) )
for ip in "${ip_addresses[@]}"; do
ip address add "$ip"/32 dev "$IFACE"
done
else
for ip in "${ip_addresses[@]}"; do
ip address del "$ip"/32 dev "$IFACE"
done
fi