X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=snmp-port-toggle.sh;h=9943ea2cbb4576baf31e15d2ca5469c55512ae53;hb=8e5fcc0e9db472b21d3d21b0882a8c469b2f575d;hp=b7fa9a70ad84a1b01730f7b2a9793219af9647be;hpb=76c04214bed9af17007290a0d018cb758ea360a1;p=dell-switch diff --git a/snmp-port-toggle.sh b/snmp-port-toggle.sh index b7fa9a7..9943ea2 100755 --- 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 @@ -8,13 +11,14 @@ 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` +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 -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 @@ -25,5 +29,8 @@ else 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