# SccsId[] = "%W% (USL function) %G%"
DFZ_name="DISPLAY_FS_SIZE"
if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
[ ."`set|egrep '^$DFZ_name\(\)\{$'`" != . ] && DFZ_loaded=1
else # Korn or Bash shell and function already loaded?
if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
[ ."`typeset +f|awk '/^'$DFZ_name'[=\(]?/'`" != . ] && DFZ_loaded=1
else # Linux
[ ."`typeset -F|awk '/^'$DFZ_name'[=\(]?/'`" != . ] && DFZ_loaded=1
fi
fi
if [ 0${DFZ_loaded} -eq 0 ]; then
#----------------------------------------------------------------------#
DISPLAY_FS_SIZE() # Function documentation located at bottom. #
#----------------------------------------------------------------------#
{ [ ."${AWK}" = . ] && { { [ -x /usr/bin/nawk ] && AWK=/usr/bin/nawk; } \
|| { [ -x /bin/gawk ] && AWK=/bin/gawk ; } \
|| { [ -x /usr/bin/awk ] && AWK=/usr/bin/awk ; }; }
if [ $# -gt 0 ]; then
$AWK \
'BEGIN \
{ #------------------------------#
# Use appropriate "df" command.#
#------------------------------#
"/bin/uname -r 2>&1" | getline os_rel
close("/bin/uname -r 2>&1")
if (os_rel ~ /^(2\.)*5/) # Linix uses "2.2.5-nn"
df_cmd="df -k" # Solaris 2.x and newer
else
df_cmd="df -t 4.2" # SunOS 4.x and older
#------------------------------#
# Display filesystem info. #
#------------------------------#
while ("/bin/"df_cmd" "ARGV[1]" 2>&1" | getline kbytes)
{
if (kbytes ~ /[0-9]%/)
{
split(kbytes,kb," ")
print kb[2], kb[3], kb[4]
exit 0 # Success
}
}
close("/bin/"df_cmd" "ARGV[1]" 2>&1")
exit 1 # If we reach this point, we failed.
}' $1
return $?
fi
#------------------------------------------#
# Reaching here means something is amiss. #
#------------------------------------------#
if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi
. $SHLIB/exit.sh # Function dependencies
. $SHLIB/email_msg.sh # Calls $SHLIB/exit.sh
#------------------------------------------------------------#
# If the following variables are not set, use these defaults.#
#------------------------------------------------------------#
: ${script_name:=`basename $0`}
: ${sp:=" "}
DFZ_ID="$script_name($DFZ_name)"
EMAIL_MSG "ERROR (Function): $DFZ_ID" \
"${sp}Insufficient args." \
"${sp}Usage: $DFZ_name filesystem (or directory)."
return 1
} # "DFZ_" prefix identifies this function's local variables.
fi
#======================================================================#
# D O C U M E N T A T I O N #
#======================================================================#
# #
# Author: Bob Orlando #
# #
# Date: March 6, 1998 #
# #
# Program ID: display_fs_size.sh #
# #
# Purpose: Display filesystem sizes (total, used, and available) #
# in kbytes. #
# #
# Usage: DISPLAY_FS_SIZE file-system | directory #
# #
# Examples: 1) home_kbytes=`DISPLAY_FS_SIZE /home` #
# Assigns, for example, "128551 18636 97065" #
# to the variable and returns $success (0). #
# 2) home_kbytes=`DISPLAY_FS_SIZE /fictitious` #
# Assigns nothing to the variable and returns #
# $failure (1). #
# #
# Globals: No global variables assigned from this function. #
# "DFZ_" prefix identifies local function variables. #
# #
# Exit_status: On success, returns zero and three blank-delimited #
# values (the filesystem's total, used, and available #
# capacities). #
# On failure, returns non-zero and a string of three #
# blank-delimited zeroes is echoed to stdout. #
# #
# Calls: EMAIL_MSG library function. #
# #
# Notes: ..................................................... #
# ..................................................... #
# #
# Modified: 2004-04-02 Bob Orlando #
# v1.8 * Expand $AWK testing and assignment. #
# #
# 2004-03-03 Bob Orlando #
# v1.7 * Change set|egrep|awk to just set|egrep. #
# #
#----------------------------------------------------------------------#
|