#!/bin/bash

# fpings all siblings from ~/.xs2siblings/siblings resp. /etc/xs2siblings except the own sibling hostname

export SLF="/etc/xs2siblings/siblings"
test -e ~/.xs2siblings/siblings && SLF=~/.xs2siblings/siblings
if [ ! -f ${SLF} ] ; then
  echo "ERROR: No sibling list, i.e. no file ~/.xs2siblings/siblings or /etc/xs2siblings/siblings"
  exit 2
fi

SHN=$(hostname -s)
export SIBLINGS=$(cat ${SLF} |egrep -v '^\s*(#|;|$)' |egrep -vi "^${SHN}(\\.|$)" |sort |uniq |cut -f1 -d':')

if [ -z "$SIBLINGS" ] ; then
  echo "ERROR: No siblings specified in ${SLF}."
  exit 3
fi

if [ ! -x /usr/bin/fping ] ; then
  echo "ERROR: No /usr/bin/fping installed, please sudo apt install -y fping"
  exit 4
fi

/usr/bin/fping $SIBLINGS

