projects
/
dell-switch
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a5028d4
)
toggle switch port using snmp
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 6 Jul 2018 16:25:58 +0000
(18:25 +0200)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Fri, 6 Jul 2018 16:25:58 +0000
(18:25 +0200)
snmp-port-toggle.sh
patch
|
blob
|
history
diff --git
a/snmp-port-toggle.sh
b/snmp-port-toggle.sh
index
b7fa9a7
..
9943ea2
100755
(executable)
--- a/
snmp-port-toggle.sh
+++ b/
snmp-port-toggle.sh
@@
-1,6
+1,9
@@
+#!/bin/sh -e
-sw=sw-a200
-PORT=19
+sw=$1
+PORT=$2
+
+test -z "$sw" -o -z "$PORT" && echo "Usage: sw-name port" && exit 1
. ./snmp.conf
. ./snmp.conf
@@
-8,13
+11,14
@@
snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
port_status() {
port_status() {
-echo
-n
"$sw $PORT "`$snmp IF-MIB::ifName.$PORT IF-MIB::ifAlias.$PORT IF-MIB::ifType.$PORT IF-MIB::ifOperStatus.$PORT IF-MIB::ifHighSpeed.$PORT`
+echo "$sw $PORT "`$snmp IF-MIB::ifName.$PORT IF-MIB::ifAlias.$PORT IF-MIB::ifType.$PORT IF-MIB::ifOperStatus.$PORT IF-MIB::ifHighSpeed.$PORT`
}
port_status
}
port_status
-read -p "# Press ENTER to toggle port" wait_for_key
+status=`$snmp IF-MIB::ifOperStatus.$PORT`
+read -p "# Press ENTER to toggle port which is now $status" wait_for_key
if [ "$status" = 'up' ] ; then
if [ "$status" = 'up' ] ; then
@@
-25,5
+29,8
@@
else
snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 1
fi
snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 1
fi
-port_status
+echo "# wait for port status change from $status"
+while port_status | tee /dev/stderr | grep $status ; do
+ sleep 1
+done