#!/bin/ksh ## ## SCRIPT NAME: chk4huge_locscr_userideas ## ## Where: in $FEDIR/scripts where FEDIR=/apps/nns_com/fea ## ############################################################################# ## PURPOSE: Checks the NNS I-DEAS CWD (current working directory) ## /local/scratch/$USER/ideas for huge directory size, using 'du'. ## ## If that directory is huge, pops a warning message to the user, ## advising them to delete the huge file(s) if possible. ## ## Provides a list of the bigger files in /local/scratch/$USER/ideas ## using the 'find' command. ## ##-------------------------------------------------------------------------- ## IMPLEMENTATION NOTES: ## ## USER-MESSAGE-NOTE: ## The message can/does include a list of the biggest files in ## that directory, or a sub-directory. And it could concentrate ## on I-DEAS err*.out files, rather than data files. ## ## DEFINITION-OF-HUGE-DIRECTORY: ## 'Huge-directory' could be defined as ## 1) a fixed number of Kbytes/Meg/Gig ## AND/OR ## 2) significant % of the size of the file system in which the ## /local/scratch directory resides. ## ## The /local/scratch directory is in its own file system on ## 'engvis00' (in 1999-2000), but the /local/scratch directory is ## a part of the the root directory on many SGI clients. ## ## For simplicity, we use ~300Meg to define 'huge-directory'. ## ## DEFINITION-OF-BIG-FILES: ## 'Big-files' could be defined as ## 1) a fixed number of Kbytes/Meg/Gig ## AND/OR ## 2) significant % of the size of the /local/scratch/$USER/ideas ## directory. ## ## We use 20% of the size of /local/scratch/$USER/ideas to define ## a 'big file' --- so that ## if we change the 'Huge-directory-size' criterion the ## 'Big-files-size' criterion changes automatically. ## ##-------------------------------------------------------------------------- ## MOTIVIATION-FOR-THIS-UTILITY: ## Such a utility was suggested by Dale Doddington E14, in Nov 2000, ## after a Tom Feldhaus I-DEAS session on 'engvis00' resulted in ## a huge 26 Gig error file that caused many FEA jobs on 'engvis00' ## to be not-runnable. ## ## A daily 'cron' job could be run to check the /local/scratch ## subdirectories on 'engvis00', but it would probably discover the ## problem many hours too late --- and only on 'engvis00'. ## ## NOTE: ## 'engvis00' was partitioned in two machines around 2002 --- ## 'engvis00' and 'engfea00'. The new 'engfea00' machine was ## to be used for FEA jobs, instead of 'engvis00'. ## ############################################################################# ## CALLED BY: NNS I-DEAS startup script --- /apps/ideas/ideas --- ## after user exits I-DEAS. I.e. the call is after the call ## to startup I-DEAS. ## ## To cover the case that the user is crashed out of I-DEAS (in ## which case, this script might not be called), one could ALSO ## call this script before the call to I-DEAS. This would ## help warn the user of huge files in the I-DEAS CWD, in the case ## that the user tries to startup I-DEAS almost immediately, after ## being crashed out. ## ############################################################################# ## TESTING-IMPLEMENTATION NOTES: ## Check the '## FOR TESTING:' statements in the script for ## 1) statements to activate, for testing ## 2) statements to DE-activate, for implementation. ############################################################################# ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 13Nov2000 Based on 'chk_locscr_sgib' ## in /usr/people/bmo01/Dscrtest ## and 'find_big_or_old_files4dir' ## & 'find_big_or_old_files4dir_bygui' ## in $FEDIR/scripts ## ## Updated by: Blaise Montandon 17Nov2000 Make 'big-file' criterion different ## from 'huge-directory' criterion. ## Make the former 20% of the latter. ## ## Updated by: Blaise Montandon 05mar2003 Add BIG_CLIENT_FEA=engfea00 to ## use $BIG_CLIENT_FEA in messages, ## in place of 'engvis00' hard-coded. ## ## Updated by: Blaise Montandon 05apr2004 To avoid a bug in new SGI 'sort' ## in IRIX 6.5.22, change ## LS_SORT_PREAWK="sort -k5nr" to ## LS_SORT_PREAWK="sort -n -r -k5". ############################################################################# ############################################################ ## SET $FEDIR DIRECTORY VARIABLE -- to use utility ## scripts, like 'set_localoutlist' & 'shofil', used below. ############################################################ if test "$FEDIR" = "" then FEDIR="/apps/nns_com/fea" fi ###################################################################### ## SET SOME VARIABLES, FOR USE BELOW -- ## $THISHOST, $DIR2CHK. Also set ## $BIGDIRinKBYTES, $BIGDIRinMEG, $BIGFILEinBYTES. ###################################################################### BIG_CLIENT_FEA="engfea00" THISHOST=`hostname` DIR2CHK="/local/scratch/$USER/ideas" #### FOR TESTING, 2000: ## DIR2CHK="/local/scratch/bmo01/ideas" ## DIR2CHK="/local/scratch/rgb07/ideas" ## DIR2CHK="/local/scratch/csb08/ideas" ## DIR2CHK="/local/scratch/drd02/ideas" #### FOR TESTING, 2003: # DIR2CHK="/local/scratch/pgm01/ideas" # DIR2CHK="/local/scratch/cjf02/ideas" # DIR2CHK="/local/scratch/jew05/ideas" # DIR2CHK="/local/scratch/kea01/ideas" ##################################################################### ## SET BIGDIRinKBYTES -- to about 100 Meg to 1 Gig (or more). ##################################################################### ## BIGDIRinKBYTES=100000 = 100 Meg ## BIGDIRinKBYTES=500000 = 500 Meg ## BIGDIRinKBYTES=1000000 = 1 Gig ##################################################################### BIGDIRinKBYTES=300000 #### FOR TESTING: ## BIGDIRinKBYTES=10 # BIGDIRinKBYTES=100 ###################################################### ## CALCULATE BIGDIRinMEG. (= BIGDIRinKBYTES / 1000) ###################################################### ## $BIGDIRinMEG is used in text msgs, not comparisons. ###################################################### ## We use 'bc' to get a decimal value for $BIGDIRinMEG. ## We use "scale = 1" to show one place to right of ## decimal point. ###################################################### BIGDIRinMEG=`echo "scale = 2; ${BIGDIRinKBYTES}/1000" | bc` # BIGDIRinMEG=`echo "scale = 1; ${BIGDIRinKBYTES}/1000" | bc` ###################################################### ## CALCULATE BIGDIRinGIG. (= BIGDIRinMEG / 1000) ## We use 'bc' to get a decimal value for $BIGDIRinGIG. ###################################################### ## $BIGDIRinGIG is not used, currently. #################################################### # BIGDIRinGIG=`echo "scale = 2; ${BIGDIRinMEG}/1000" | bc` ################################################################ ## CALCULATE BIGFILEinBYTES --- used in 'find' statement below. ################################################################ ## We set BIGFILEinBYTES using 20% (one-fifth) of BIGDIRinKBYTES. ################################################################ ## BIGFILEinBYTES=`expr $BIGDIRinKBYTES \* 1000 / 5` ## or in simplified form: BIGFILEinBYTES=`expr $BIGDIRinKBYTES \* 200` ################################################################ ## CALCULATE BIGFILEinMEG --- used in title of BigFiles list below. ################################################################ ## $BIGFILEinMEG is used in text msgs, not comparisons. ################################################################# ## We use 'bc' to get a decimal value for $BIGFILEinMEG. ## We use "scale = 1" to show one place to right of ## decimal point. ################################################################# ## BIGFILEinMEG = BIGDIRinKBYTES / 1000 / 5 ## or in simplified form: ## BIGFILEinMEG = BIGDIRinKBYTES / 5000 ################################################################# BIGFILEinMEG=`echo "scale = 2; ${BIGDIRinKBYTES}/5000" | bc` # BIGFILEinMEG=`echo "scale = 1; ${BIGDIRinKBYTES}/5000" | bc` ############################################# ## GET THE DIRECTORY SIZE (in Kbytes) ## of the $DIR2CHK directory. ############################################# ## FOR TESTING: # set -x DIRSIZE_KBYTES=`du -ks $DIR2CHK | cut -f1` # DIRSIZE_KBYTES=`du -ks $DIR2CHK | awk '{print $1 }'` ## FOR TESTING: # set - ############################################# ## CHECK THAT THE DIRECTORY SIZE WAS ## DETERMINED SUCCESSFULLY WITH 'du'. ############################################# if test "$DIRSIZE_KBYTES" = "" then JUNK=`xconfirm -c -header "I-DEAS BIG FILES - Warning" \ -B DISMISS \ -t "chk4huge_locscr_userideas:" \ -t "" \ -t " There appears to be a problem with this I-DEAS session." \ -t "" \ -t " The directory $DIR2CHK" \ -t " (the I-DEAS Current Working Directory for this site)" \ -t " does not seem to be available." \ -t "" \ -t " Please call an I-DEAS Administrator to report this" \ -t " problem." \ -icon warning` & exit fi ############################################# ## CALCULATE THE DIRECTORY SIZE (in MEG) ## for messages below. ############################################# DIRSIZE_MEG=`echo "scale = 2; ${DIRSIZE_KBYTES}/1000" | bc` ################################################ ## 'ASSIGNMENT' STATEMENTS TO SET FLAGS FOR MSGS. ################################################ DIRSIZE_MSG="YES" FILSIZES_LIST="YES" # DIRSIZE_MSG="NO" # FILSIZES_LIST="NO" ################################################ ## POPUP WARNING MSG IF $DIR2CHK IS 'BIG'. ################################################ ## FOR TESTING: # set -x if test \( $DIRSIZE_KBYTES -gt $BIGDIRinKBYTES -a "$DIRSIZE_MSG" = "YES" \) then if test "$FILSIZES_LIST" = "YES" then LIST_MSG="A list of the bigger files is shown now, in another window." fi JUNK=`xconfirm -c -header "I-DEAS BIG FILES - Warning" \ -B DISMISS \ -geometry +750+750 \ -t "I-DEAS Current Working Directory $DIR2CHK" \ -t "on this machine, $THISHOST," \ -t "is VERY BIG --- bigger than $BIGDIRinMEG MEGabytes:" \ -t "$DIRSIZE_MEG MEGabytes." \ -t "" \ -t "PLEASE LOOK FOR BIG FILES TO DELETE (OR MOVE) --- " \ -t "like huge I-DEAS 'err*.out' files, OR big-unneeded DATA files," \ -t "in the I-DEAS Current Working Directory $DIR2CHK." \ -t "" \ -t "It is especially important to delete/move huge files promptly on" \ -t "SHARED machines, like '$BIG_CLIENT_FEA'. You can use the 'rm' command to" \ -t "remove files. Dragging to Dumpster moves them to your home directory." \ -t "" \ -t "You can use the site 'spacetools' utility to get size (or age)" \ -t "sorted lists of files in that directory. Or you can use 'ls -l'" \ -t "to see file sizes, in bytes, unsorted." \ -t "" \ -t "$LIST_MSG" \ -icon warning` & fi ########################################################################### ## END OF if test $DIRSIZE_KBYTES -gt $BIGDIRinKBYTES ## ## --- TO POP-UP A WARNING OF THE SIZE OF THE DIRECTORY. ########################################################################### ## YOU CAN QUICKLY DE-ACTIVATE THIS 'DIRSIZE' POPUP BY CHANGING THE ## "$DIRSIZE_MSG"="YES" *ASSIGNMENT* STATEMENT TO, SAY, ## "$DIRSIZE_MSG"="NO". ########################################################################### ############################################################################ ## BUILD A LIST OF 'BIG' FILES IN $DIR2CHK (size-sorted) -- using 'find'. ## SHOW THE LIST IN A SCROLLABLE WINDOW. ############################################################################ ## This list of big files can be shown IN ADDITION TO -or- ## IN PLACE OF the big-diretory popup msg above, by use of ## the $DIRSIZE_MSG and $FILSIZES_LIST vars. ############################################################################ ## An alternative, using 'ls' instead of 'find': ## A way of showing a size-sorted list of ALL the files in the directory: ## ## ls -l $DIR2CHK | grep -v '^d' | sort -nr -k5 ############################################################################ if test \( $DIRSIZE_KBYTES -gt $BIGDIRinKBYTES -a "$FILSIZES_LIST" = "YES" \) then ############################################################ ## Set a filename for HUGE-FILES-report output, in $OUTLIST. ############################################################ . $FEDIR/scripts/set_localoutlist rm -f $OUTLIST ############################################################ ## PREPARE REPORT HEADING, in $OUTLIST. ############################################################ echo "\ ******************************** `date '+%Y %b %d %a %T%p %Z'` ****************** LIST OF BIG FILES (bigger than $BIGFILEinMEG MEGabytes) IN ${THISHOST}:$DIR2CHK Owner FileSize(Meg) Permissions Userid GigMeg.KilByt Date-Time Filename ---------- -------- | | | | ------------ ------------------------------ " > $OUTLIST ############################################################ ## PREPARE LIST OF HUGE FILES (SIZE-SORTED), in $OUTLIST. ############################################################ REFMT_LS_CMD="eval awk '{printf (\"%-13s %-8s %13.6f %3s %2s %5s %s\n\", \$1, \$3, \$5/1000000, \$6, \$7, \$8, \$NF)}'" # LS_SORT_PREAWK="sort -k5nr" LS_SORT_PREAWK="sort -n -r -k5" ## FOR TESTING: # set -x find $DIR2CHK -local -type f \ -size +${BIGFILEinBYTES}c -exec ls -l {} \; | \ $LS_SORT_PREAWK | $REFMT_LS_CMD >> $OUTLIST ## FOR TESTING: # set - ############################################################ ## ADD A TRAILER TO REPORT, in $OUTLIST. ############################################################ echo " ******************************** `date '+%Y %b %d %a %T%p %Z'` ****************** Please delete (or move) any huge files that you can --- to avoid future inability to run applications because of lack of space for files in /local/scratch. It is especially important to delete/move huge files promptly on SHARED machines, like '$BIG_CLIENT_FEA'. Files smaller than $BIGFILEinMEG MEGabytes are not shown. If there are no files shown above, this is a sign that the space occupied by $DIR2CHK ($DIRSIZE_MEG MEGabytes) is made up of many files that are smaller than $BIGFILEinMEG MEGabytes. ........................................................................... " >> $OUTLIST ########################################################### ## SHOW THE REPORT. ########################################################### $FEDIR/scripts/shofil $OUTLIST fi ##################################################################### ## END OF if test $DIRSIZE_KBYTES -gt $BIGDIRinKBYTES ## ## --- TO PREPARE LIST OF HUGE FILES. ##################################################################### ## YOU CAN QUICKLY DE-ACTIVATE THIS BIG-FILES LISTING BY CHANGING THE ## "$FILSIZES_LIST"="YES" *ASSIGNMENT* STATEMENT TO, SAY, ## "$FILSIZES_LIST"="NO". #####################################################################