Skip to content

Instantly share code, notes, and snippets.

@nshobe
Last active December 4, 2017 17:51
Show Gist options
  • Save nshobe/e90fdbc5789ba6554013256a03a47985 to your computer and use it in GitHub Desktop.
Save nshobe/e90fdbc5789ba6554013256a03a47985 to your computer and use it in GitHub Desktop.
Check Network Redundancy
#!/bin/bash
PATH=/sbin:/usr/sbin:$PATH
# Validate being run as root/sudo
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
# Check for tools and find bonded interfaces
if [ `which systool &>/dev/null; echo $?` -gt 0 ]; then
echo "No Tool: Systool"
exit 1
fi
if which ip &>/dev/null; then
BONDS=( $(ip link | awk {'print $2'} | grep "^bond[0-9]\+:" | sed 's/://') )
elif which ifconfig &>/dev/null; then
BONDS=( $(ifconfig -a -s | awk {'print $1'} | grep "^bond[0-9]\+ ") )
else
echo "No Tool: ip/ifconfig"
exit 1
fi
if [ ${#BONDS[@]} -eq 0 ]; then
printf "No bonded interface"
fi
# Iterate across each bonded interface, to ensure each is redundant for both ports and card functionality
for BOND in "${BONDS[@]}"; do
printf "$BOND:"
# Check Ports for bonded interface
if [ `ip link | grep $BOND | wc -l` -ge 2 ]; then
printf "Yes"
else
printf "No"
fi
# Empty temp file
>$BOND.device
# Generate list of interfaces for bond
PORTS=( $(ip link | grep ${BONDS[@]} | awk {'print $2'} | sed 's/://') )
# Write PCI Port for each network port used by bond to temp file
for PORT in ${PORTS[@]}; do
systool -c net -d $PORT | grep -i device | grep -vi class | awk -F: {'print $2'} >>$BOND.device
done
# Validate more than one PCI port is in use for bond
if [ `cat $BOND.device | sort -u | wc -l` -ge 2 ]; then
printf "&Yes "
else
printf "&No "
fi
# Clean up
rm $BOND.device
done
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment