#!/bin/ksh ## ## SCRIPT: host2host_info4allfiles_4dir_showBYgui ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: For a given Host & Directory ( passed in vars $1 & $2 ), ## this script creates an 'ls -al' info report, ## for the files in the LOCAL or REMOTE host:directory. ## ## Prompts the user (with 'xconfirm' or a similar Tk GUI) for 3 ## sort options: name sort, age-sort, size-sort ## ## Puts the report into a temp-file (on the host running this script) ## and shows the report file with shofil_ver2.tk (the 'xpg' utility). ## ## Checks for 2 arguments and checks that the host:directory exists. ## In either case, if not, Pops an 'xconfirm' error msg and exits. ############################################################################## ## CALLED BY: host2host_fileman.tk in $FEDIR/tkGUIs ############################################################################## ## CALL FORMAT (2 examples): ## ## $FEDIR/scripts/filesel_info4allfiles_4dir_showBYgui \ ## cvxprd00 /CDMDATA/modcop ## ## $FEDIR/scripts/filesel_info4allfiles_4dir_showBYgui \ ## engprd00 /data/cvn78/division ## ############################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 03dec2001 Based on scripts ## 'filesel_info4allfiles_4dir_showBYgui' & ## 'diruse_files_onelevel_sizesort_bygui' & ## 'diruse_files_onelevel_agesort_bygui' ## in $FEDIR/scripts ## and a remote-directory existence check in ## 'host2host_fileman.tk' in $FEDIR/tkGUIs. ## ## Updated by: Blaise Montandon 10jan2002 1) Use 'ls -lAp' twice with 'grep' to ## show dirs first, then files. ## 2) When field9 (filename) contains ## embedded blanks, awk shows only ## first segment of filename. ## For now, do not use awk formatting. ## ## Updated by: Blaise Montandon 08apr2004 To avoid a bug in new SGI 'sort' ## in IRIX 6.5.22, changed several cases ## of 'sort -k5nr' to 'sort +4 -5nr'. ############################################################################## THISHOST=`hostname` ############################################################################# ## Set scripts pathname in case this toolchest is not started from ## the nnsFEAmenu system --- and a $FEDIR utility script (or help) is needed. ############################################################################# if test "$FEDIR" = "" then FEDIR=/apps/nns_com/fea export FEDIR fi ############################################################ ## Assure that the DISPLAY variable is set. ## Set to do X-displays on this host. ############################################################ # # if test "${DISPLAY}" = "" # then # DISPLAY="$THISHOST:0" # export DISPLAY # fi ############################################################ ## If this is a remote login, ## set X-display to the remote host. ############################################################ # if test ! "$REMOTEHOST" = "" # then # REMOTEHOST1=`echo $REMOTEHOST | cut -d. -f1` # DISPLAY="$REMOTEHOST1:0" # export DISPLAY # fi ############################################################ ## Set dirHOST & DIRNAME vars using $1 & $2 -- and check ## that they are not null. ############################################################ ## FOR TESTING: # set -x dirHOST="$1" DIRNAME="$2" if test "$dirHOST" = "" then xconfirm -c -header "NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 2 inputs --- host name & directory name." \ -t "" \ -t "No host was specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi if test "$DIRNAME" = "" then xconfirm -c -header "NO_INPUT_warning" \ -B Dismiss \ -t "The script" \ -t " $0" \ -t "needs 2 inputs --- host name & directory name." \ -t "" \ -t "No directory was specified. Exiting..." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit fi ############################################################ ## Check that the directory exists. ## If not, exit with msg. ############################################################ ## Directory-Existence-Check for a local host is followed ## by a check for a remote-host directory. ############################################################ if test "$dirHOST" = "$THISHOST" then if test ! -d "$DIRNAME" then xconfirm -c -header "DIRECTORY_NOT_FOUND_warning" \ -B Dismiss \ -t "The directory $DIRNAME " \ -t "is NOT KNOWN TO host $dirHOST." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test ! -d "$DIRNAME" fi ## END OF if test "$dirHOST" = "$THISHOST" if test ! "$dirHOST" = "$THISHOST" then ## WORKS, for no embedded blanks in $DIRNAME. # RETcode=`rsh $dirHOST \ # "if test -d $DIRNAME ; then echo 1 ; else echo 0 ; fi"` RETcode=`rsh $dirHOST \ "if test -d \"$DIRNAME\" ; then echo 1 ; else echo 0 ; fi"` if test $RETcode = 0 then xconfirm -c -header "DIRECTORY_NOT_FOUND_warning" \ -B Dismiss \ -t "The directory $DIRNAME " \ -t "is NOT KNOWN TO host $dirHOST." \ -t "" \ -t "*EXITING*." \ -icon warning > /dev/null # -font $CONFIRM_FONT \ exit # break # continue fi ## END OF if test $RETcode = 0 fi ## END OF if test ! "$dirHOST" = "$THISHOST" ############################################################ ## Ask for sort -- by name or age or size? ############################################################ SORT_TYPE=`xconfirm -c -header "SORT by NAME or AGE or SIZE?" \ -b CANCEL -b SIZE -b AGE -B NAME \ -t "In the report, sort the files of directory" \ -t "" \ -t " ${dirHOST}:$DIRNAME" \ -t "" \ -t "by NAME -OR- AGE -OR- SIZE ?" \ -icon warning` # -font $CONFIRM_FONT \ if test "$SORT_TYPE" = "CANCEL" then exit fi ################################################################### ## PREPARE REPORT FILENAME -- in $OUTLIST. ################################################################### . $FEDIR/scripts/set_localoutlist ################################################################### ## Set a common message for the trailer of the 3 reports ## -- in $XPG_MSG. ################################################################### XPG_MSG="\ SELECTING LINES OF THE REPORT -- via a string-pattern: When you browse the report with the 'xpg' utility, you may want to extract/see just those lines that contain a certain string. To do that, you can use the 'ShowAllMatches' button with the plus-or-minus N lines option, with N set to zero (0). Three examples: 1) To see all files containing the string 'out', put the string 'out' (without the quotes) in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. For examples 2 & 3, note that for DIRECTORIES, the permissions info starts with 'd' and usually starts with 'dr' -- in fact, usually 'drwx'. The permisions info for (non-directory) FILES starts with '-' and usually starts with '-r' -- in fact, usually '-rw'. Hence: 2) To see the files-lines and NOT the directory-lines of the report, put '-r' in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. 3) To see the directories-lines and NOT the nondirectory-file-lines of the report, put 'dr' in the String entry field of the 'xpg' GUI. Set N to 0 and click the 'ShowAllMatches' button. " ########################################################################## ########################################################################## ## FOLLOWING ARE THREE BIG 'if' SECTIONS --- for ## SORT_TYPE = NAME -OR- AGE -OR- SIZE ########################################################################## ########################################################################## ########################################################################## ## PREPARE THE 'SORT_TYPE = NAME' REPORT. ########################################################################## if test "$SORT_TYPE" = "NAME" then if test "$dirHOST" = "$THISHOST" then ## FOR TESTING: # set -x # LS_OUT=`ls -al "$DIRNAME"` LS_OUT_DIRS=`ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - else ## FOR TESTING: # set -x # LS_OUT=`rsh $dirHOST ls -al "$DIRNAME"` LS_OUT_DIRS=`rsh $dirHOST ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`rsh $dirHOST ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - fi ## END OF if test "$dirHOST" = "$THISHOST" ######################################### ## PREPARE THE 'NAME' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory ${dirHOST}:$DIRNAME (directory names, then file names; case-sensitive) SORTED BY ** NAME ** This report was generated by running the 'ls -lAp' command on $dirHOST , and the report was assembled on and presented from $THISHOST . ************* Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- " > $OUTLIST ########################################## ## PREPARE THE 'NAME' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x echo "$LS_OUT_DIRS" >> $OUTLIST echo "$LS_OUT_FILS" >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lAp' command on host $THISHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be accessed via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, SIZE-SORT)'. or 'Show FILE-SIZES 4aDir@AnyHost (ONE level, AGE-SORT)'. Those utilities sort by file size & age -- not by name. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "NAME" ####################################### ########################################################################## ## PREPARE THE 'SORT_TYPE = AGE' REPORT. ########################################################################## if test "$SORT_TYPE" = "AGE" then if test "$dirHOST" = "$THISHOST" then ## FOR TESTING: # set -x # LS_OUT=`ls -alt "$DIRNAME"` LS_OUT_DIRS=`ls -lApt "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lApt "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - else ## FOR TESTING: # set -x # LS_OUT=`rsh $dirHOST ls -alt "$DIRNAME"` LS_OUT_DIRS=`rsh $dirHOST ls -lApt "$DIRNAME" | grep '/$'` LS_OUT_FILS=`rsh $dirHOST ls -lApt "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - fi ## END OF if test "$dirHOST" = "$THISHOST" ######################################### ## PREPARE THE 'AGE' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory ${dirHOST}:$DIRNAME SORTED BY ** AGE ** --- NEWEST (or most recently modified) DIRECTORIES AT THE TOP of the directories, and NEWEST (or most recently modified) FILES AT THE TOP of the files. This report was generated by running the 'ls -lApt' command on $dirHOST , and the report was assembled on and presented from $THISHOST . ************* Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- |" > $OUTLIST ########################################## ## PREPARE THE 'AGE' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x ## echo "$LS_OUT" | tail +2 | \ ## awk '{printf ("%13.6f %-10s %-8s %-8s %-3s %2s %5s %s\n", $5/1000000, $1, $3, $4, $6, $7, $8, $9 )}' \ ## >> $OUTLIST echo "$LS_OUT_DIRS" >> $OUTLIST echo "$LS_OUT_FILS" >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lApt' command on host $dirHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be run via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, AGE-SORT). Since that utility is intended to help with file cleanup, it shows the oldest files first. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "AGE" ####################################### ########################################################################## ## PREPARE THE 'SORT_TYPE = SIZE' REPORT. ########################################################################## if test "$SORT_TYPE" = "SIZE" then if test "$dirHOST" = "$THISHOST" then ## FOR TESTING: # set -x # LS_OUT=`ls -al "$DIRNAME"` LS_OUT_DIRS=`ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - else ## FOR TESTING: # set -x # LS_OUT=`rsh $dirHOST ls -al "$DIRNAME"` LS_OUT_DIRS=`rsh $dirHOST ls -lAp "$DIRNAME" | grep '/$'` LS_OUT_FILS=`rsh $dirHOST ls -lAp "$DIRNAME" | grep -v '/$' | grep -v '^total'` ## FOR TESTING: # set - fi ## END OF if test "$dirHOST" = "$THISHOST" ######################################### ## PREPARE THE 'SIZE' REPORT HEADING. ######################################### echo " ********************* `date '+%Y %b %d %a %T%p %Z'` ****************** FILE INFO for the directories, then the files, in the directory ${dirHOST}:$DIRNAME SORTED BY ** SIZE ** --- BIGGEST DIRECTORY 'INDEXES' AT THE TOP of the directories, and BIGGEST FILES AT THE TOP of the files. This report was generated by running the 'ls -lAp' command on $dirHOST , and the report was assembled on and presented from $THISHOST . ************* Disk usage Last-Modified Permissions Owner Group (Bytes) Date-time Filename ----------- -------- -------- ------------- ----------- ---------------------------------- " > $OUTLIST ########################################## ## PREPARE THE 'SIZE' REPORT CONTENT. ########################################## ## FOR TESTING: # set -x ## echo "$LS_OUT" | tail +2 | sort +4 -5nr | \ ## awk '{printf ("%13.6f %-10s %-8s %-8s %-3s %2s %5s %s\n", $5/1000000, $1, $3, $4, $6, $7, $8, $9 )}' \ ## >> $OUTLIST # echo "$LS_OUT_DIRS" | sort -k5nr >> $OUTLIST # echo "$LS_OUT_FILS" | sort -k5nr >> $OUTLIST echo "$LS_OUT_DIRS" | sort +4 -5nr >> $OUTLIST echo "$LS_OUT_FILS" | sort +4 -5nr >> $OUTLIST ## FOR TESTING: # set - ########################################### ## ADD A TRAILER TO THE REPORT-FILE. ########################################### echo "\ ----------- -------- -------- ------------- ----------- ---------------------------------- Permissions Owner Group (Bytes) Date-time Filename Disk usage Last-Modified ..................... `date '+%Y %b %d %a %T%p'` ............................ The output above was generated by the script $0 which ran the 'ls -lAp' command on host $THISHOST . ------------------------- $XPG_MSG -------------------- SUB-DIRECTORIES NOTE: A line that starts with 'd' in the permissions string shows the size of the 'index' ('pointers') of a directory -- NOT the size of all the files and subdirectories under that directory. ------------------------- SIMILAR UTILITY ELSEWHERE: A similar utility can be accessed via a drawer in a 'spacetools' toolchest command-utility --- via a drawer with a name like 'Show FILE-SIZES 4aDir@AnyHost (ONE level, SIZE-SORT)'. ---------------------------------------------------------------------------- " >> $OUTLIST fi ####################################### ## END OF if test "$SORT_TYPE" = "SIZE" ####################################### ################################################################### ## SHOW the 'ls -al' report (sorted by name or age or size). ################################################################### $FEDIR/scripts/shofil $OUTLIST