There are lots of ways to do this. Obviously nsradmin is the key, but you can package this up in various languages to format the output, perl, awk, shell etc. For a fairly trivial query like this I would just knock up a short shell script. I can think of two different approaches to this:
(1) List all clients and their storage nodes field. Complication with this is that the storage nodes field can hold multiple values, such as:
"nodeA"
"nodeA, nodeB"
so sorting them might not group the clients together as you might wish.
(2) Specify a storage node and query all clients using it. This way, a query for "nodeA" will match both examples above, but a query for "nodeB" will only match the latter. nsradmin is quite clever sometimes.
Let's use (1) for an example script below.
Code:
#!/bin/ksh
# showclientsbynode
SERVER=${1:-$(uname -n)}
echo "
show name; storage nodes
print type: NSR client
" | nsradmin -s $SERVER -i - | sed 's/;//' | while read LINE; do
ATT=$(echo $LINE | cut -d: -f1 | sed 's/^ //')
VAL=$(echo $LINE | cut -d: -f2 | sed 's/^ //')
if [ "$ATT" = "name" ]; then
NAME=$VAL
elif [ "$ATT" = "storage nodes" ]; then
SNODE=$(echo $VAL | sed 's/,/ /g')
echo "$SNODE,$NAME"
fi
done | sort -u
Output is CSV format suitable for reading in to most spreadsheet packages.
Or if we want to do (2) it could look like this:
Code:
#!/bin/ksh
# queryclientsbynode
SNODE=$1
if [ -z "$1" ]; then
echo "Specify storage node"
exit 1
fi
SERVER=${2:-$(uname -n)}
echo "
show name
print type : NSR client;
storage nodes : $SNODE
" | nsradmin -s $SERVER -i - | sed 's/;//' | while read LINE; do
ATT=$(echo $LINE | cut -d: -f1 | sed 's/^ //')
VAL=$(echo $LINE | cut -d: -f2 | sed 's/^ //')
[ "$ATT" = "name" ] && echo $VAL
done | sort -u
Neither of the scripts have much in the way of bells and whistles (error checking, comments etc.) as I just knocked them up in 5 minutes, but it should give you the general idea of how it can be done.