#!/bin/ksh ## ## SCRIPT: dfk_filsys_anyhost_bygui ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ########################################################################## ## PURPOSE: Shows the disk usage (in 1K blocks translated to Gig) in ## all file systems on any SGI host on the NNS network. ## ## A Tcl-Tk script presents a GUI that prompts for hostid. ## The entry field is initialized with the hostname of the ## SGI host on which this script is running. ## ########################################################################## ## CALLED BY: spacetools in $FEDIR/scripts ## ## and, perhaps someday, by ## feamain -> feautils.menu -> fileman.menu script ## in $FEDIR/scripts ########################################################################## ## A LESSON LEARNED THE HARD WAY (~1995): ## DO NOT USE 'gr_osview' for filesystem space display; does updates every ## few seconds instead of a one-time query. Reference: ## gr_osview -D/apps/nns_com/fea/scripts/grosview_parmfilesys ## ########################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon O06 14Oct1999 Based on 'dfk_thishost_server' ## & 'dfk_main' in $FEDIR/scripts ## Updated by: Blaise Montandon O06 14Mar2000 Chg Kbytes to Gig. Also ## chg sort to %Used rather than ## Mount-dir-name. Reformat. ## Updated by: Blaise Montandon O06 6Sep2000 Add 'Unknown host' check. ## ## Updated by: Blaise Montandon 01may2003 1) Add $0 info to $WIN_INFO of GUI. ## 2) Replace the Tk-GUI ## 'enter_hostid_optmenu.tk' by ## 'enter_hostid_optmenu_toghelp-scroll.tk'. ## ## Updated by: Blaise Montandon 23sep2003 Load HOST_ID var from script arg $1 ## --- or env-var. If not loaded ## (i.e. = "") then use the previous ## defaults. ## ## Updated by: Blaise Montandon 05apr2004 To avoid a bug in new SGI 'sort' ## in IRIX 6.5.22, changed 3 cases of ## 'sort -k6nr' to ## 'sort -n -r -k6'. ## ## Updated by: Blaise Montandon 12may2004 'Touch-up' help info in the WIN_INFO ## var and in the report trailer. ########################################################################## ############################################################################# ## SET A UTILITY SCRIPTS PATHNAME in case this toolchest is not started from ## the HandyTools toolchest or the nnsFEAmenu toolchest --- and a ## $FEDIR utility script (or help file) is needed. ############################################################################# if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi ############################################################################## ## SET query hostname from script arguments 1 ## --- if not already set. ############################################################################## if test "$HOST_ID" = "" then HOST_ID="$1" fi ############################################################################## ## SET LOCAL HOST NAME FOR MESSAGES & REPORTS & LOCAL-HOST-CHECKS. ############################################################################## THISHOST=`hostname` ########################################################################## ## SET 'CONSTANT' PARMS of the GUI that prompts for hostname. ## Also set a default HOSTID for the GUI. ######################################################################## WINTITLE="FileSysSizes_AnyHost (incl. %-Used)" export WINTITLE WIN_INFO="\ INPUT: ----- Select or enter the name of an SGI host on the NNS network. (If necessary, you can enter an IP-address.) ------ OUTPUT: ------ This utility shows the disk usage (in Gigabytes) in the file systems of the specified host. The 'local' file systems are shown first, and then the remote (NFS-mounted) file systems. And in each group, the file systems are shown in %-used order --- i.e. fullest first. Typically, it takes 1 to 10 seconds to generate this report. ----- USAGE: ----- The report from this utility is especially helpful to check whether 'local' disk file systems on the specified host are full or nearly full. The report format (with disk-space figures in Gigabytes, in aligned columns) is much more readable than the 'raw' output from the 'df' command. ---- Note that you can do queries on multiple hosts and bring the report windows side-by-side for comparison. And you can quickly generate printouts. ---------- ADMIN INFO: ---------- This GUI is presented by the 'wrapper' script $0 This 'wrapper' script also performs the report generation --- with a df-sed-sort-awk 'pipe' of commands --- and shows the report." export WIN_INFO # WIN_GEOM="+40+40" # export WIN_GEOM ########################## ## Set a default hostID. ########################## # HOSTS_LIST="`hostname` engfea00 engvis00 engprd00 ews###" # export HOSTS_LIST if test "$HOST_ID" = "" then HOST_ID="`hostname`" fi export HOST_ID ##################################################################### ## PROMPT for hostID. ##################################################################### ## HOST_ID=`$FEDIR/tkGUIs/enter_hostid.tk` # HOST_ID=`$FEDIR/tkGUIs/enter_hostid_optmenu.tk` HOST_ID=`$FEDIR/tkGUIs/enter_hostid_optmenu_toghelp-scroll.tk` if test "$HOST_ID" = "" then exit fi ##################################################################### ## CHECK THAT THE HOST_ID EXISTS, if not THISHOST. ##################################################################### ## FOR TESTING: # set -x if test ! "$HOST_ID" = "$THISHOST" then HOSTCHECK=`rsh $HOST_ID cd 2>&1 | grep 'Unknown host'` if test ! "$HOSTCHECK" = "" then CONFIRM_TEXT="\ Specified Host: $HOST_ID is Unknown. " export CONFIRM_TEXT CONFIRM_GEOM="+080+080" CONFIRM_MINSIZE="350 150" CONFIRM_TITLE="$WINTITLE" export CONFIRM_TITLE CONFIRM_MINSIZE CONFIRM_GEOM CONFIRM_COLOR="#3DADFF" export CONFIRM_COLOR CONFIRM_FONT="-adobe-helvetica-bold-r-normal--*-100-*-*-p-*-*-*" export CONFIRM_FONT JUNK=`$FEDIR/tkGUIs/confirm.tk DISMISS` & exit ## continue fi fi ########################################################################## ## SET OUTPUT FILENAME, local if possible. ########################################################################## . $FEDIR/scripts/set_localoutlist ########################################################################## ## SET REPORT HEADING. ########################################################################## echo "\ ......................... `date '+%Y %b %d %a %T%p %Z'` ........................ DISK USAGE (in Gigabytes) IN FILE SYSTEMS ON HOST *** $HOST_ID *** SORTED BY *PERCENT-USED* --- HIGHEST %-USED AT THE TOP ************ " > $OUTLIST DATAHEAD="\ FileSystem ****** ALLOCATED USED AVAILABLE ${HOST_ID}-Device-partition (xfs) Directory (Filesystem Mount Point) % USED Gigabytes Gigabytes Gigabytes Type OR Server:Directory (nfs) ----------------------------------- ------ ---------- ---------- ---------- ---- -------------------------------------" ########################################################################## ## GENERATE REPORT CONTENTS. (from Local or Remote host) ########################################################################## ########################################################################## ## Cannot get multi-field reverse/numeric sorts to work; even with ## tab-to-blank translate in 'sed'. ## Workaround: Use separate 'local' and 'nfs' runs of 'df' below. ## ## CMD="eval sed '1d;s/\ / /g' | /usr/bin/sort -k2r,2r -k6nr,6nr | /usr/bin/awk \ ## '{printf (\"%-35s %6s %11.3f %10.3f %10.3f %-5s %s \n\n\", \$7, \$6, \$3/1000000, \$4/1000000, \$5/1000000, \$2, \$1)}'" ########################################################################## ########################################################################## ## Cannot get various attempts with single-quotes instead of double-quotes ## to work. Use double-quotes and escape-" and escape-$ and escape-space below. ## ## CMD='sed ''1d'' | /usr/bin/sort -k6nr | /usr/bin/awk \ ## ''{printf ("%-35s %6s %11.3f %10.3f %10.3f %4s %s \n\n", $7, $6, $3/1000000, $4/1000000, $5/1000000, $2, $1)}''' ########################################################################## # CMD="eval sed '1d' | /usr/bin/sort +5nr -6 | /usr/bin/awk \ CMD="eval sed '1d' | /usr/bin/sort -n -r -k6 | /usr/bin/awk \ '{printf (\"%-35s %6s %11.3f %10.3f %10.3f \ %-4s %s \n\n\", \$7, \$6, \$3/1000000, \$4/1000000, \$5/1000000, \$2, \$1)}'" ## FOR TESTING: # echo "CMD: $CMD" THISHOST=`hostname` if test "$HOST_ID" = "$THISHOST" then echo " ****************** LOCAL FILE-SYSTEMS: ****************** $DATAHEAD " >> $OUTLIST ## FOR TESTING: # set -x /usr/sbin/df -kl | $CMD >> $OUTLIST ## FOR TESTING: # set - echo " ************************* REMOTE (NFS) FILE-SYSTEMS: ************************* $DATAHEAD " >> $OUTLIST ## FOR TESTING: # set -x /usr/sbin/df -k -Fnfs | $CMD >> $OUTLIST ## FOR TESTING: # set - else ############################################ ## MAKE .rhosts FILE FOR THE USER, if needed. ############################################ . $FEDIR/scripts/mak_rhosts echo " ****************** LOCAL FILE-SYSTEMS: ****************** $DATAHEAD " >> $OUTLIST ## FOR TESTING: # set -x rsh $HOST_ID /usr/sbin/df -kl | $CMD >> $OUTLIST ## FOR TESTING: # set - echo " ************************* REMOTE (NFS) FILE-SYSTEMS: ************************* $DATAHEAD " >> $OUTLIST ## FOR TESTING: # set -x rsh $HOST_ID /usr/sbin/df -k -Fnfs | $CMD >> $OUTLIST ## FOR TESTING: # set - ########################################################### ## REMOVE .rhosts FILE FOR THE USER. (Commented; not used.) ########################################################### # . $FEDIR/scripts/mv_rhosts fi ########################################################################## ## ADD REPORT 'TRAILER'. ########################################################################## SERVER="engprd00" BASENAME=`basename $0` echo " ......................... `date '+%Y %b %d %a %T%p'` ........................ This utility shows LOCAL FILE SYSTEMS first. It also shows REMOTE (NFS-mounted) FILE SYSTEMS (if any) that are mounted on this host from other file servers. NOTE1: This file-systems report is SORTED by %-Used, LARGEST %-Used FIRST --- within the 'LOCAL FILE-SYSTEMS' group and within the 'REMOTE (NFS) FILE-SYSTEMS' group. NOTE2: The %-Used and other data for the REMOTE file-systems is 'suspect'. For ACCURATE size data on a REMOTE file-system, QUERY THE HOST SERVING that file-system. For example, the mounted directory $SERVER:/data may actually include multiple file-systems on $SERVER. If you do this query on a host other than '$SERVER', the %-USED figure shown for the remote /data directory will correspond to only ONE file-system --- when /data MAY be composed of SEVERAL file-systems. Hence ... To get the complete picture for a mounted-directory (which may consist of multiple file-systems, i.e. separate disk-space allocations), query the host serving the directory (and its file-systems). ............................................................................. The output above is from script $0 which ran the 'df' command on host $HOST_ID . The script uses a 'pipe' of several commands (df, sort, awk) like: df -kl | sort -n -r -k6 | awk '{printf ( ... ) }' and df -k -Fnfs | sort -n -r -k6 | awk '{printf ( ... ) }' ............................................................................. NOTE: This utility provides formatting (in Gigabytes) and sorting that is not available by use of only the 'df' command. ............................................................................. ------------------------------ IMPLEMENTATION OF THIS UTILITY: ------------------------------ The '$BASENAME' script can be accessed via a drawer in a site HandyTools-SpaceTools toolchest. The site SGI toolchest-drawer path is SGI Toolchest -> Handy Tools -> SpaceTools -> Show FILE-SYSTEM-SIZES @AnyHost (%-USED SORT), 'df' ............................................................................. " >> $OUTLIST ########################################################################## ## SHOW REPORT. ########################################################################## $FEDIR/scripts/shofil $OUTLIST