document solution
[dell-switch] / snmp-port-toggle.sh
1 #!/bin/sh -e
2
3 sw=$1
4 PORT=$2
5
6 test -z "$sw" -o -z "$PORT" && echo "Usage: sw-name port" && exit 1
7
8 . ./snmp.conf
9
10 snmp="snmpget -v 2c -c $COMMUNITY -Cf -Ov -OQ $sw"
11
12 port_status() {
13
14 echo "$sw $PORT "`$snmp IF-MIB::ifName.$PORT IF-MIB::ifAlias.$PORT IF-MIB::ifType.$PORT IF-MIB::ifOperStatus.$PORT IF-MIB::ifHighSpeed.$PORT`
15
16 }
17
18 port_status
19
20 status=`$snmp IF-MIB::ifOperStatus.$PORT`
21 read -p "# Press ENTER to toggle port which is now $status" wait_for_key
22
23 if [ "$status" = 'up' ] ; then
24
25         # down
26         snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 2
27 else
28         # up
29         snmpset -v1 -c $COMMUNITY $sw IF-MIB::ifAdminStatus.$PORT i 1
30 fi
31
32 echo "# wait for port status change from $status"
33 while port_status | tee /dev/stderr | grep $status ; do
34         sleep 1
35 done
36