Created
July 21, 2016 10:43
-
-
Save kevinbenton/e179b2994c62f21b5a92a170ec649b6b to your computer and use it in GitHub Desktop.
looking for ofport re-use while port still exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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