#!/bin/ksh ## ## SCRIPT: diruse_subdirs_onelevel_2stdout ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ########################################################################### ## PURPOSE: For a specified directory residing-on (or known/mounted-to) the ## host on which this script runs, this script creates a list ## (to standard out) that ## ## shows the disk usage (in 1K blocks) in sub-directories of ## a user-specified directory -- ONE LEVEL DOWN (no more). ## ## This script is a utility script called by the GUI pre-processor script ## 'diruse_subdirs_onelevel_bygui' in $FEDIR/scripts. ## ## More info on the calling script and calling format is below. ########################################################################### ## PERFORMANCE NOTE: ## ## In some cases, like where there are many 'dense' sub-directory ## trees, it may actually be faster to run the ## 'diruse_subdirs_all_bygui' script, which shows the disk usage ## in ALL levels of subdirectories of a user-specified directory ## --- rather than run this 'onelevel' script. ## ## This is because the 'all' script does one 'du' call, whereas this ## 'onelevel' script does one 'du' call for each 1st-level directory. ## ## This utility may be slow when there are a lot of 'large' 1st-level ## directories. ## ## Since 'du' probably traverses the entire directory structure ## under the specified directory in either script, it may ## prove to be better to do the one 'du' call and just throw away ## all the output lines for lower-level subdirectories. A ## 'grep -v' technique could be used with a mask consisting of ## slashes separated by wildcards --- like /.*/.*/.... with the ## wildcards going one level lower than the specified directory. ## ## Ref: $FEDIR/scripts/find_big_or_old_files4dir ## ############################################################################## ## MAIN/ORIGINAL INTENT: ## The main intent is to identify the biggest sub-directories ## immediately under a given directory -- to help with file ## cleanup in out-of-file-system-space conditions. Example dirs: ## ## Directory Host of the directory (1999-2000) ## --------------------- --------------------- ## /usr/people/$USER engprd00 ## /data/subs/cae engprd00 ## /local/scratch engvis00 or iaw### ## /var iaw### or engvis00 or engprd00 ## /apps engprd00 ## ############################################################################# ## CALLED BY: diruse_subdirs_onelevel_bygui ## in $FEDIR/scripts ## which is called via a 'spacetools' toolchest drawer: ## ## SGI Toolchest -> ## HandyTools -> ## AnyHost - SpaceTools (Files) -> ## Show SUBDIR-SIZES 4aDir@AnyHost (ONE level,SIZE-SORT) ## ## Also can be called manually, for example --- on a local ## iaw### host or via login to 'engprd00' and 'engfea00'. ## ## Could be put in a 'ideasadm' cron job (in /apps/ideas/cron) ## or in a 'caeadm' cron job (in /usr/people/caeadm/cron). ## ############################################################################## ## CALL FORMAT (examples): See diruse_subdirs_onelevel_bygui ## ## $FEDIR/scripts/set_localoutlist ## $FEDIR/scripts/diruse_subdirs_onelevel_2stdout /local/scratch \ ## > $OUTLIST ## ## xpg $OUTLIST ## #### where the one positional argument is used to set vars: #### DIRNAME #### in this script ## ## OR ('rsh' form) ## ## $FEDIR/scripts/set_localoutlist ## rsh engvis00 $FEDIR/scripts/diruse_subdirs_onelevel_2stdout \ ## /local/scratch > $OUTLIST ## ## xpg $OUTLIST ## ############################################################################# ## NOTE: You can see only the non-commented, executable lines of this ## script by using ## egrep -v '^ *##|^ *# ' ## or ## grep -v '^ *##' | grep -v '^ *# ' ############################################################################# ## MAINTENANCE HISTORY of predecessor script 'diruse_subdirs_onelevel': ## Written by: B. Montandon O06 15Mar2000 Based on 'duseanydir_onelevel' ## and 'diruse_subdirs_all_bygui' ## and 'find_big_or_old_files4dir' ## in $FEDIR/scripts. ## Updated by: B. Montandon O06 21Sep2000 Chg from Kbytes to Megabytes and ## add a decimal point. ## Updated by: Blaise Montandon 21mar2001 Chg TEMPLIST from ${OUTLIST}_unsorted ## to $HOME/temp_du_one_level_unsorted ############################################################################# ## MAINTENANCE HISTORY of this script 'diruse_subdirs_onelevel_2stdout': ## ## Updated by: Blaise Montandon 06mar2001 Made this script ## 'diruse_subdirs_onelevel_2stdout' ## from 'diruse_subdirs_onelevel' by ## removing '> $TEMPLIST' statements. ## ## Updated by: Blaise Montandon 03apr2003 Chg 'ls -l' to 'ls -Al'. ############################################################################## ############################################################################## ## SET THE MAIN PARAMETER TO BE USED BELOW. ############################################################################## DIRNAME="$1" if test "$DIRNAME" = "" then echo " Script $0 needs a as input. " exit fi ############################################################################## ## SET THE LIST OF DIRECTORIES IMMEDIATELY BELOW THE SPECIFIED DIR. ############################################################################## ## ONE WAY (not good): ## DIRLIST=`ls -1ad "$DIRNAME/*" ## Might fail if * generates too many matches. ## ## That's a 'one' in front of the 'd', not 'ell'. ############################################################################## ## Would like to find a way to generate the list without using the '-l' ## parameter of 'ls', which requires looking up a lot of unused info. ## ## Candidate: ## ls -Ap "$DIRNAME" | grep "/$" | sed "s|/$||" ############################################################################## # DIRLIST=`ls -al "$DIRNAME" | grep "^d"| awk '{ print $NF }'` DIRLIST=`ls -Al "$DIRNAME" | grep "^d"| awk '{ print $NF }'` ## FOR TESTING: # echo $DIRLIST # exit ########################################################################### ## SEND 'du -ks' OUTPUT FOR EACH SUB-DIRECTORY TO stdout -- from this host. ########################################################################### ######################################################################## ## Pop a message to the screen about the directory being non-local ## --- and better performance running on the directory's remote server. ######################################################################## ## LOCALCHK=`stat $DIRNAME | grep nfs` ## ## if test "$LOCALCHK" != "" ## then ## ## echo " ## ........................................................................... ## ${HIbold}NOTE:${HIreset} ## Directory $DIRNAME ## is mounted on this workstation from a server (probably 'engprd00'). ## ## This utility will probably perform faster if you remote login ## to that server and then run the utility. ## " ## ## fi ######################################################################### ######################################################################### ## Send the total space occupied by the TOP-LEVEL, SPECIFIED directory -- ## to stdout. ######################################################################### du -ks $DIRNAME ######################################################################### ## Send the total space for EACH SUBDIRECTORY of the specified directory ## -- to stdout. ######################################################################### for DIR in $DIRLIST do # if test "$DIR" = "." # then # continue # fi # if test "$DIR" = ".." # then # continue # fi ## FOR TESTING: # set -x du -ks $DIRNAME/$DIR ## FOR TESTING: # set - done