So when you need to find which cart/port corresponds to which jack, it can get messy - here's a simple script (easily adapted to other scenarios) to simplify:
#!/bin/bash
# simple script to calc the card/port pair, given the patch cable #
# - result is returned as an integer, in format: port + (100 * card#)
# History:
#
# 20070523 mvgfr: incep
# minimal error trapping:
if [ -z "$1" ] ; then exit 0; fi
if [ "$1" -le 0 ] ; then exit 0; fi
patch=$1
# fudge for discountinuity; jump from card #8 to #13 (since there are no port cards in slots 9-12)
if [ "$patch" -gt 192 ] ; then let patch+=96 ; fi
card=$(( ( ( $patch * 100 / 24 ) + 99 ) / 100 ))
port=$(( $patch - ( ( $card - 1 ) * 24 ) ))
echo "$card, $port"
result=$(( ( $card * 100 ) + $port))
echo $result
exit $result #send the result back as the exit code, for potential further processing...
#end
No comments:
Post a Comment