#! /bin/ksh ## ## SCRIPT: duseanydir_onelevel ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ######################################################################## ## PURPOSE: Shows the disk usage (in 1K blocks) in subdirectories of ## a user-specified directory -- ONE LEVEL DOWN (no more). ## ######################################################################## ## CALLED BY: feamain -> feautils.menu -> fileman.menu script ## ######################################################################## ## MAINTENANCE HISTORY: ## Written by: B. Montandon O06 13Mar2000 Based on duseanydir and ## find_big_or_old_files4dir in ## $FEDIR/scripts. ## Updated by: B. Montandon O06 13Mar2000 ######################################################################## if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi # set -x ######################################################################## ## START OF PROMPTING LOOP, FOR DIRECTORY NAME. ######################################################################## # while true while : do ######################################################################## ## GET DIRECTORY NAME. ######################################################################## . $FEDIR/scripts/clearnns echo "${HIbold}\ ........................................................................... DiskUse-in-SubDirs: Show disk usage in *SUB-DIRECTORIES ONE-LEVEL* below a given directory known to `hostname` (largest subdirectory to smallest) ${HIreset} Enter a DIRECTORY NAME ... fully qualified or relative to current directory. ${HIbold} Examples: ${HIdim} your 'subs' CAE data:${HIreset} /data/subs/cae/$USER ${HIdim} your 'nuclear' CAE data:${HIreset} /data/nuclear/cae/$USER ${HIdim} your 'carrier' CAE data:${HIreset} /data/carrier/cae/$USER ${HIdim} your 'other' (DoubleEagle) CAE data:${HIreset} /data/other/cae/$USER ${HIdim} subs I-DEAS work & team data:${HIreset} /data/subs/ideas ${HIdim} nuclear I-DEAS work & team data:${HIreset} /data/nuclear/ideas ${HIdim} carrier I-DEAS work & team data:${HIreset} /data/carrier/ideas ${HIdim}other (DoubEagle) I-DEAS work&team data:${HIreset} /data/other/ideas ${HIdim} subs I-DEAS work (in-process) data:${HIreset} /data/subs/ideas/team/datamgmt# ${HIdim} subs I-DEAS team (check-in) data:${HIreset} /data/subs/ideas/team/shared# ${HIdim} Local work area:${HIreset} /local/scratch ${HIdim} Local $USER work area:${HIreset} /local/scratch/$USER ${HIdim} Local I-DEAS work area:${HIreset} /local/scratch/ideas ${HIdim} User preferences data:${HIreset} $HOME ${HIdim} parent of current directory:${HIreset} .. ${HIdim} current directory:${HIreset} . ${HIdim} WARNING: A summary of the /usr/people subdirectories, i.e. the user Home directories, may take many minutes. See nnsFEAmenu option 'u f uh' for a weekly Home-dirs report. ${HIreset} Current Directory: $PWD ${HIbold}\ (mouse-)Enter DIRECTORY NAME (or null to EXIT) ==>${HIreset} \c" read dirname1 if test "${dirname1}" = "" then break # exit fi if test ! -d "${dirname1}" then echo " ${dirname1} is not a directory. *** Press Enter to continue." read NNS_JUNK continue # exit fi if test "${dirname1}" = "/" then echo " Try a lower level directory than the root directory (/). *** Press Enter to continue." read NNS_JUNK continue # exit fi ############################################################################## ## 'cd' TO THE SPECIFIED DIR and RESET IT TO ITS FULLY-QUALIFIED NAME. ## (de-activated; let's not change directories on the user) ############################################################################## ## set -x ## cd ${dirname1} ## set - ## dirname1=`pwd` ############################################################################## ## SET THE LIST OF DIRECTORIES IMMEDIATELY BELOW THE SPECIFIED DIR. ############################################################################## DIRLIST=`ls -l "$dirname1" | grep "^d"| awk '{ print $NF }'` ## FOR TESTING: # echo $DIRLIST # exit ######################################################################## ## Prep report HEADING on size of sub-directories. ######################################################################## . $FEDIR/scripts/set_localoutlist echo "\ .....................`date`............................ Disk usage (in 1K blocks) in sub-directories of directory ${dirname1} ONE-LEVEL DOWN (no further). Total usage is shown on first line. Disk usage (1K blks) Subdirectory name ------------- ------------------------ TerGigMegKil | | | |" > $OUTLIST ######################################################################## ## Get report data from an SGI server if the directory is NSF-mounted. ######################################################################## ## Old method of dealing with local vs. NFS directory: ## if test \("${dirname1}" = "/local" -o "${dirname1}" = "/local/scratch" \) LOCALCHK=`stat ${dirname1} | grep nfs` if test "$LOCALCHK" != "" then ######################################################################## ## Pop a message to the screen about the directory being non-local ## --- and better performance running on the directory's remote server. ######################################################################## echo " ........................................................................... ${HIbold}NOTE:${HIreset} Directory ${dirname1} is mounted on this workstation from a server (probably 'engprd00'). This utility will probably perform much faster if you remote login to that server and then run the utility. " fi TEMPLIST="${OUTLIST}_unsorted" rm -f $TEMPLIST du -ks ${dirname1} >> $TEMPLIST for DIR in $DIRLIST do du -ks ${dirname1}/$DIR >> $TEMPLIST done sort +0 -1 -nr $TEMPLIST | \ awk '{printf ("%13s %s\n", $1, $2 )}' >> $OUTLIST rm $TEMPLIST ######################################################################## ## Add TRAILER to report. ######################################################################## echo "\ ........................................................................ The output above was generated by the script $0 Uses commands like : ls -l \"$dirname1\" | grep \"^d\" | awk '{ print \$NF }' TO BUILD THE SUBDIRECTORY LIST; du -ks ${dirname1}/ TO GET THE SIZE OF EACH SUBDIRECTORY; sort +0 -1 -nr TO SORT THE SUBDIRECTORIES BY SIZE, IN DESCENDING ORDER; awk '{printf ( ... )}' TO RIGHT-JUSTIFY THE SIZES. This report can be generated via nnsFEAmenu option 'u f ud1' (Utilities, File-tools, Used-by-subDirectories-OneLev). Or it can be a drawer in the 'spacetools' command-utility, which you can implement as - a command alias, via your .profile file; - a desktop icon, via the 'Find, File QuickFind' tool drawers; - a drawer in the SGI toolchest, via your .auxchestrc file. ........................................................................ " >> $OUTLIST ######################################################################## ## SHOW REPORT, with option to print. ######################################################################## . $FEDIR/scripts/shofil $OUTLIST # set - ######################################################################## ## RETURN TO DIRECTORY PROMPT. ######################################################################## done ######################################################################## ## END OF prompting loop, for directory name. ########################################################################