#!/bin/sh
#< Display disk statistics
# kw 10/01/2004

# usage: diskstat    - prints all disk info
#        diskstat /dev/hda1 - print for /dev/hda1 only
#        diskstat -? or --help - print usage

#Create temp files
df_i_tmp=$HOME/tmp/df_i.tmp
df_mT_tmp=$HOME/tmp/df_mT.tmp
df_all=$HOME/tmp/df_all.tmp

#Populate temp files
df -i > $df_i_tmp
df -mT > $df_mT_tmp

join $df_i_tmp $df_mT_tmp | sed '1d' > $df_all

trap 'rm -f $HOME/tmp/df*.tmp; exit 1' 1 2 3 15

_mode="normal"
if [ "$#" -eq "1" ]; then
  _mode="single"
fi

if [ "$#" -ge "2" ]; then
  echo "USAGE: `basename $0` [device]" && exit 1
fi

if [ "$1" == "-?" -o  "$1" == "--help" ]; then
  echo "USAGE: `basename $0` [device]" && exit 1
fi

while read line
do
   _filesystem=$( echo $line | awk '{ print $1 }' )
   if [ "$_mode" == "single" ]; then
      if [ "$1" != "$_filesystem" ]; then
          continue
      fi
   fi
   _inodes=$( echo $line | awk '{ print $2 }' )
   _iused=$( echo $line | awk '{ print $3 }' )
   _ifree=$( echo $line | awk '{ print $4 }' )
   _iuse=$( echo $line | awk '{ print $5 }' )
   _mountpoint=$( echo $line | awk '{ print $6 }' )
   _type=$( echo $line | awk '{ print $7 }' )
   _1mblocks=$( echo $line | awk '{ print $8 }' )
   _used=$( echo $line | awk '{ print $9 }' )
   _available=$( echo $line | awk '{ print $10 }' )
   _use=$( echo $line | awk '{ print $11 }' )
   _format='%20s%20s\n'

   echo "========================================"
   echo "Filesystem $_filesystem"
   echo "========================================"
   printf $_format "Mounted at" $_mountpoint
   printf $_format "FS Type" $_type
   printf $_format "Total size MB" $_1mblocks
   printf $_format "Used MB" $_used
   printf $_format "Available MB" $_available
   printf $_format "Total FS Usage" $_use
   echo -e "\n"
   printf $_format "Total Inodes" $_inodes
   printf $_format "Used Inodes" $_iused
   printf $_format "Free Inodes" $_ifree
   printf $_format "Inode Usage" $_iuse 
   echo -e "\n"
done < $df_all

# cleanup
rm -f $HOME/tmp/df*.tmp

exit 0