#!/bin/csh -f
#+
# disks -- print out a listing of available data disks
#
# Purpose:
#   Prints out a list of data disks attached to the instrument computer, 
#   sorted by their available disk space.
#
# Usage:
#	disks [-n]
# 
# Arguments:
#	-n = do not print header
# 
# Output:
#	Results written to stdout
# 
# Restrictions:
#	None
# 
# Exit values:
#	 0 = normal completion
#	 1 = wrong number of arguments
#
# Example:
#	1) List currently available data disks on punaluu:
#
#		disks
#
#	   The following sample output is received:
#	
#		Data disks available on punaluu, ordered by available space:
#
#		                  kbytes   Fraction
#		Disk              avail.     used
#		-----------------------------------
#		/sdata220       13897104    (21%)
#		/sdata222        7897104    (50%)
#		/sdata221          97104    (99%)
# 
# 	2) List currently available data disks on punaluu without
#	   header information:
#	
#		disks -n
#
#	   The following sample output is received:
#	
#		/sdata220       13897104    (21%)
#		/sdata222        7897104    (50%)
#		/sdata221          97104    (99%)
#-
# Modification history:
#	Date unknown	RWG	Original version
#	2000-Oct-18	GDW	-Added documentation
#				-Added "-n" flag
#	2002-Oct-18	GDW	Changes to support /sdata
#-----------------------------------------------------------------------

# verify args...
if ( $#argv > 1 ) then
  set buf = $0
  set cmd = $buf:t
  echo "Usage: $cmd"
  exit 1
endif

# use "rsh" if needed to run remotely on instrument host...
set computer = polo
set hostname = `hostname | sed 's/\..*$//'`
if ( "$hostname" != "$computer" ) then
    set cmd = "rsh $computer"
else
    set cmd = ""
endif

# print optional header...
if ( "$1" != "-n" ) then

cat<<EOF
Data disks available on $computer, ordered by available space:

                  kbytes   Fraction
Disk              avail.     used
-----------------------------------
EOF

endif

# generate list...
$cmd /usr/ucb/df -lk | awk '/sdata100.$/{printf "%s %14d    (%s)\n",$6,$4,$5}' \
    | /usr/bin/sort -nr -k 2