Listing 1
#!/bin/sh -
# dkmap queries hosts to get useful information about
# shared disks mounted in a local network. Each host
# in the host list requires an entry in your trusted
# host lists (usually /etc/hosts.equiv).
# Copyright: Dorian Deane, 1992
trap 'echo Operation Interrupted; /bin/rm -f /tmp/*.$$; \
exit 1' 2 3 15
echo ""
# Remember, all hosts must be in hosts.equiv or /.rhosts
if [ $# -gt 1 ]; then # if defined on command line
HOST_LIST=$*
else
HOST_LIST='host1 host2 host3 host4 hostn'
fi
# A pre-defined host list is not as elegant as
#
# HOST_LIST=`grep nnn\.nnn\.\[0-99\]\[0-99\] \
# /etc/hosts | /bin/sed 's/.* //' | /bin/sed 's/ .*//'
`
#
# but works better in an imperfect world
# DISK_LIST is appropriate for "off the rack"
# Suns. You'll need to modify yours appropriately.
# On Suns, use "sr" to see CD-ROM capacity.
DISK_LIST="sd xy"
NL='
'
ARCH=/bin/arch # These programs are
DF=/bin/df # variously named on
DKINFO=/etc/dkinfo # different machines.
DEVICE=
SUBTOTAL=0 # The script gets totals for
BIGTOTAL=0 # diskspace, but they're not necessary,
HOSTTOTAL=0 # merely a convenience.
# Some date programs have better syntax--this is more portable.
set `date`
OFS=$IFS # A trick to reset IFS, later.
echo ""
echo ""
echo " SYSTEM-WIDE DISK INFORMATION"
echo " " $2 $3, $6
echo ""
for HOST in $HOST_LIST
do
echo ""
echo " " ****$HOST****
# PART I -- a simple df:
echo ""
echo "Locally Mounted Files Systems on $HOST"
echo ""
rsh $HOST $DF -t 4.2 # The -t option is a Sun-ism.
echo "" # For non-Suns, try
# "rsh $HOST df | grep -v : "
# PART II -- get import info. in a nice format
echo ""
echo $HOST Imports the Following Files:
echo ""
echo "Source Local Name on $HOST" # 5 tabs
rsh $HOST cat /etc/mtab | grep : | \
/bin/sed 's/nfs.*//' | \
tr " " "\011\011\011\011\011" # \011 = tab
echo ""
# PART III -- get disk labels
# The general idea is to copy a nested script to the
# remote machine, execute it, and save the output to
# a temporary file on the local machine. This may
# seem strange, but it saves many rsh's.
rsh $HOST cat <<EOF ">" /tmp/dkfind.$$
#!/bin/sh -
case `$ARCH` in
sun*) DKINFO=/etc/dkinfo ;;
gould) DKINFO=/etc/diskpart ;;
3b2) DKINFO=/etc/devinfo ;;
# Insert your machine-type here!
*) echo unknown machine type ;;
esac
echo " " DISK LABELS for $HOST
echo ""
for DISK in $DISK_LIST
do
# This assumes no more than 10 disks per machine
set -- "0" "1" "2" "3" "4"
"5""6" "7" "8" "9"
for NUMBER in \$*
do
$DKINFO \${DISK}\${1} 2> /dev/null | grep -v "no such disk"
if [ \$? -eq 0 ]; then
echo ""
fi
shift
done
done
EOF
rsh $HOST sh /tmp/dkfind.$$ > /tmp/dkfound.$$ # execute it.
rsh $HOST /bin/rm /tmp/dkfind.$$ # remove it.
cat /tmp/dkfound.$$
# set IFS to newline
IFS=$NL
# Look at c: partition--defined as entire disk in most Un*x.
for RECORD in `grep "^c:" /tmp/dkfound.$$`
do
# (Remember, two seds are better than one awk!)
SUBTOTAL=`echo $RECORD|/bin/sed 's/c: //'|/bin/sed 's/ .*//'`
HOSTTOTAL=`/usr/bin/expr ${HOSTTOTAL} + ${SUBTOTAL}`
done
IFS=$OFS
echo ""
# Assume sector size of 512 bytes.
echo TOTAL for $HOST is `/bin/expr $HOSTTOTAL / 2` Kb
echo ""
SUBTOTAL=0
BIGTOTAL=`/usr/bin/expr ${BIGTOTAL} + ${HOSTTOTAL}`
HOSTTOTAL=0
echo "-------------------------------------------------------------------"
done
echo ""
echo TOTAL CAPACITY OF ALL DISKS is `/usr/bin/expr $BIGTOTAL / 2` Kb
/bin/rm /tmp/*.$$ # clean up
|