toggle port up/down (with ENTER confirmation)
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 28 Jun 2018 21:06:45 +0000 (23:06 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 28 Jun 2018 21:06:45 +0000 (23:06 +0200)
snmp-port-toggle.sh [new file with mode: 0755]

diff --git a/snmp-port-toggle.sh b/snmp-port-toggle.sh
new file mode 100755 (executable)
index 0000000..b7fa9a7
--- /dev/null
@@ -0,0 +1,29 @@
+
+sw=sw-a200
+PORT=19
+
+. ./snmp.conf
+
+snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
+
+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`
+
+}
+
+port_status
+
+read -p "# Press ENTER to toggle port" wait_for_key
+
+if [ "$status" = 'up' ] ; then
+
+       # down
+       snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 2
+else
+       # up
+       snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 1
+fi
+
+port_status
+