show all roots, use log git repository
[dell-switch] / spanning-tree-check.sh
1 #!/bin/sh
2
3 # check for files older than day
4
5 find log -name '*active*' -ctime +1  | cut -d_ -f2 | while read sw ; do
6         echo "# /dell-switch.pl $sw 'show spanning-tree active'"
7         ./dell-switch.pl $sw 'show spanning-tree active'
8 done
9
10 m_path=../mikrotik-switch
11 find $m_path/out -name '*bridge monitor 0 once' -ctime +1 | cut -d/ -f4 | cut -d. -f1 | while read sw ; do
12         echo "# $m_path/m-ssh-out $sw 'interface bridge monitor 0 once'"
13         $m_path/m-ssh-out $sw 'interface bridge monitor 0 once'
14 done
15
16 (
17
18 #git -C log grep STP | grep -v RSTP | grep 'spanning-tree active' | sed -e 's/_/ /g'  | awk '{ print $2" .*"$6 }' > /tmp/st.1.patt
19
20 echo "# active roots"
21 #git -C log grep -B 2 root '*active*'
22 git -C log grep -B 4 'switch is' '*active*'
23 #git -C log grep -B 4 'regional Root' '*active*'
24 #git -C log grep -B 3 'CST ROOT' '*active*'
25 git -C $m_path/out grep -C 1 'root-bridge: yes'
26
27 echo "# root bridge"
28 (
29 git -C $m_path/out grep root-bridge-id | cut -d. -f 1,3 | sed 's/\./ /'
30 git -C log grep -A 4 'Root ID' '*active*' | grep Address | sed 's/_/ /g' | awk '{ print $2 " " $7 }'
31 ) | sort -k 2 | column -t
32
33 echo "# STP only (RSTP ignored) -- should be empty if OK"
34 git -C log grep STP | grep -v RSTP | grep 'spanning-tree active' | tee /tmp/st.2.full | sed -e 's/_/ /g'  | awk '{ print $6"\t"$2"[ \t$]" }' > /tmp/st.2.patt
35 grep -f /tmp/st.2.patt /dev/shm/neighbors.tab | column -t
36
37 ) | ./filter_mac_add_hostname | tee /dev/shm/$( basename $0 ).out
38 test -z "$DEBUG" && git -C /dev/shm commit -m "$( date +%Y-%m-%d ) $( basename $0 )" $( basename $0 ).out