Skip to content

Instantly share code, notes, and snippets.

@kevinbenton
Created July 21, 2016 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinbenton/e179b2994c62f21b5a92a170ec649b6b to your computer and use it in GitHub Desktop.
Save kevinbenton/e179b2994c62f21b5a92a170ec649b6b to your computer and use it in GitHub Desktop.
looking for ofport re-use while port still exists
#!/bin/bash
FNAME=$1
file $1 | grep gzip >/dev/null
if [ $? -eq 1 ]; then extract_com=cat; else extract_com=gzcat; fi
interfaces=$($extract_com $FNAME | grep " added interface " | grep "on port" | awk -F 'added interface ' '{ print $2 }' | awk -F ' on port ' '{ print $2 "!!" $1 }' | sort | uniq )
for i in $interfaces; do
ofport=$(echo $i | awk -F '!!' '{ print $1 }')
intf=$(echo $i | awk -F '!!' '{ print $2 }')
all_on_port=$($extract_com $FNAME | grep "on port $ofport\$" | grep interface)
THIS_ACTIVE=0
THIS_FIRST_LINE=''
OTHER_ACTIVE=0
OTHER_FIRST_LINE=''
while read -r line; do
if [[ "$line" =~ "$intf on port" ]]; then
if [[ $THIS_ACTIVE -eq 0 ]]; then
THIS_ACTIVE=1
THIS_FIRST_LINE=$line
fi
if [[ $OTHER_ACTIVE -eq 1 ]]; then
echo "Potential conflict for $intf"
echo $THIS_FIRST_LINE
echo $OTHER_FIRST_LINE
echo $line
continue 2
fi
else
if [[ $THIS_ACTIVE -eq 1 ]]; then
if [[ $OTHER_ACTIVE -eq 0 ]]; then
OTHER_FIRST_LINE=$line
fi
OTHER_ACTIVE=1
fi
fi
done <<< "$all_on_port"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment