-
Notifications
You must be signed in to change notification settings - Fork 2
/
toggle-dead-switch-port.sh
executable file
·68 lines (53 loc) · 1.89 KB
/
toggle-dead-switch-port.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh -e
if [ -z "$1" ] ; then
#cat /dev/shm/sw.dead | while read sw ; do
fping -u $( ./sw-names ) | tee /dev/shm/sw.dead | while read sw ; do
./$0 $sw
done
exit 0
fi
sw=$1
echo "XXX $sw"
grep $sw /dev/shm/neighbors.tab | grep ^sw-dpc | sed 's/\t/ /g' | while read on_sw on_if mac to_port to_switch rest ; do
echo "# [$on_sw] [$on_if]"
m=/home/dpavlin/mikrotik-switch
# cat << _MIKROTIK_
# # admin@sw-dpc-2] > /interface ethernet print where comment="sw-aula"
# # [admin@sw-dpc-2] > /interface ethernet print brief where comment="sw-aula"
# # [admin@sw-dpc-2] > /interface ethernet disable 0
# #[admin@sw-dpc-2] > /interface ethernet enable 0
# _MIKROTIK_
#echo "/interface ethernet print where comment=\"$sw\""
#echo "/interface ethernet disable"
#echo ~/mikrotik-switch/m-ssh $on_sw
$m/m-ssh-out $on_sw '/interface ethernet print' | grep $sw'.$'
# cr/lf line endings, so end of line is .$
port_nr=$( grep $sw'.$' ../mikrotik-switch/out/$on_sw*ethernet*print | awk '{ print $1 }' )
echo "## $on_sw $port_nr -> $sw"
test -z "$port_nr" && echo "no port for $sw on $on_sw" && exit 1
$m/m-ssh $on_sw "/interface ethernet disable $port_nr"
sleep 5
$m/m-ssh $on_sw "/interface ethernet enable $port_nr"
echo "XXX if ping $sw doesn't work, try"
echo "XXX $m/m-ssh $on_sw '/interface bridge port set 2 edge=yes'"
echo "XXX ./ssh.sh $sw # show spanning-tree active # and fix it"
echo "XXX $m/m-ssh $on_sw '/interface bridge port set 2 edge=auto'"
done
grep ^$sw /dev/shm/neighbors.tab | sed 's/\t/ /g' | while read sw if mac on_port on_switch rest ; do
echo "# [$on_switch] [$on_port]"
# # [sw-aula] [g22]
# dpavlin@black:~/dell-switch$ ./ssh.sh sw-aula
# configure
# interface ethernet g22
# shutdown
# no shutdown
# exit
# exit
# exit
# # [sw-lib] [Gi1/0/51]
# configure
# interface Gigabitethernet 1/0/51
#
echo "RUN MANUALLY IF CORRECT"
echo ./ssh-switch-port-down-up $on_switch $on_port
done