We do have some customers, who get charged on a monthly basis for their SAN usage. We already had “reporting” in place, but that wasn’t very flexible. So I went ahead and rewrote the current reporting script from scratch, and this is what I’ve come up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#/bin/bash # LICENSE: GNU General Public License v2. (see LICENSE.txt) # COPYRIGHT: Copyright 2010 Christian Heim <christian.heim@barfoo.org> svc_sshkey="~/.ssh/svc-id_dsa" svc_addr="10.144.0.150" svc_user="admin" if [ -z $1 ] ; then echo "Please rerun this script with some kind of filter value" echo "(for example '$0 NAS')" exit 1 else filter=$1 fi IFS=" " DISK="$( ssh -i $svc_sshkey -l $svc_user $svc_addr svcinfo lsvdisk -nohdr -bytes -delim : | egrep -i "V.*$filter" | cut -d: -f2,8 | sort )" # Get a unique list of systems SYSTEMS="$( echo $DISK | sed "s, ,n,g" | cut -d -f1 | sed 's,^V,,' | cut -d_ -f1 | sort -u )" for system in $SYSTEMS ; do VDISKS="$( echo $DISK | sed "s, ,n,g" | grep $system | sed "s,:,: ," )" SYSTEM_TOTAL="$( echo $DISK | sed "s, ,n,g" | grep $system | cut -d: -f2 | awk '{SUM += $1} END { printf "%.2f", SUM }' )" for vdisk in $VDISKS ; do NAME="$( echo $vdisk | cut -d: -f1 )" SIZE="$( echo $vdisk | cut -d: -f2 | sed "s,^ ,," )" GB_SIZE="$( echo "$SIZE / 1024 / 1024 / 1024" | bc )" if [ $GB_SIZE -eq 0 ] ; then GB_SIZE="$( echo "scale=2; $SIZE / 1024 / 1024 / 1024" | bc )" GB_SIZE="${GB_SIZE/./0.}" fi echo "$NAME: ${GB_SIZE/./,} GB" done SUB_TOTAL_SYSTEM="$( echo "scale=2; $SYSTEM_TOTAL / 1024 / 1024 / 1024" | bc )" echo "SUB TOTAL: ${SUB_TOTAL_SYSTEM/./,} GB" echo done TOTAL="$( echo $DISK | sed "s, ,n,g" | cut -d: -f2 | awk '{SUM += $1} END { printf "%.2f", SUM }' )" TOTAL="$( echo "scale=2; $TOTAL / 1024 / 1024 / 1024" | bc ) GB" echo "------------------------------------------------" echo $TOTAL exit 0 |
I gotta say, once again I learned a lot … two new things about awk!
I know the report itself doesn’t look *that* pretty, but it serves a purpose!