#!/bin/ksh ## ## SCRIPT: dir_ls_stat_info ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: This script is used to get the 'ls -ld' info for a DIRECTORY, and ## replace the modify-time info by the 'full'-modify-time info ## provided by the 'stat' command. ## ## The 'ls' command, unfortunately, gives the modify-time in two ## different formats: ## ## 1) without the year, when the file s less than a year old ## and ## 2) wthout the 24-hr-time, when the file is more than a year old. ## ## This script uses the 'stat' command to get the 'full' modify-time. ## See example formats in comments below. ############################################################################## ## CALLED BY: ## script 'divclean_shoALLsubdirs4dir_butDivViz_agesort_bygui' ## in $FEDIR/scripts ## and perhaps eventually in other utility scripts. ############################################################################## ## INPUT: a DIRECTORY name, preferably fully-qualified. ## ## NOTE: The input DIRECTORY-name is typically coming from a ## 'find ... -type d ...' ## command like the example shown in the 'FOR TESTING' ## section below. ############################################################################## ## OUTPUT: a file-info line, echoed to 'standard out'. ############################################################################## ## FOR TESTING: : Can paste the following at a shell-command prompt: ## ## find -local -type d \ ## -exec /apps/nns_com/fea/scripts/dir_ls_stat_info "{}" \; ## ## where is a directory name like ## /local/scratch/$USER ## ## NOTE: We need quotes around filenames, to handle file names with ## embedded spaces. ############################################################################## ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 03sep2003 Based on script 'file_ls_stat_info' ## in $FEDIR/scripts ## Updated by: Blaise Montandon 03sep2003 ############################################################################### DIRNAME="$1" if test "$DIRNAME" = "" then echo " Script $0 needs a DIRECTORY name --- preferably fully-qualified, like from a 'find -type d ....' command, for a given fully-qualified directory name. Exiting ... " exit fi ########################################################################### ## GET ALL 'ls -ld' output for the DIRECTORY. ## ## EXAMPLE: ## $ ls -ld /apps/nns_com/fea/Dscrtest ## ## drwxr-xr-x 4 bmo01 user 16384 Sep 2 18:24 /apps/nns_com/fea/Dscrtest ## ########################################################################### ## FOR TESTING: (TURN THIS OFF WHEN THROUGH TESTING!!) # set -x # LS_OUT=`ls -ld "$DIRNAME"` LS_OUT=`ls -ld "$DIRNAME" 2> /dev/null` ########################################################################## ## GET 'modify time' 'stat' output for the DIRECTORY. ## EXAMPLE: ## $ stat /apps/nns_com/fea/Dscrtest ## ## /apps/nns_com/fea/Dscrtest: ## inode 272971795; dev 1048582; links 4; size 16384 ## directory; mode is rwxr-xr-x; uid 2250 (bmo01); gid 20 (user) ## projid 0 st_fstype: nfs3 ## change time - Tue Sep 2 18:24:29 2003 <1062541469> ## access time - Wed Sep 3 06:29:06 2003 <1062584946> ## modify time - Tue Sep 2 18:24:29 2003 <1062541469> ## ########################################################################## STAT_MODTIME=`stat "$DIRNAME" 2> /dev/null | grep 'modify time -' | awk '{print $8 " " $5 " " $6 " " $7}'` ########################################################################## ## GET FIELDS 5,1,3,4 of $LS_OUT (size-in-bytes, permissions,uid,gid) ## EXAMPLE: ## 16384 drwxr-xr-x bmo01 user ## of ## drwxr-xr-x 4 bmo01 user 16384 Sep 2 18:24 /apps/nns_com/fea/Dscrtest ## ########################################################################## LS_REFORMAT_PRE=`echo "$LS_OUT" | awk '{print $5 " " $1 " " $3 " " $4}'` ########################################################################## ## PUT TOGETHER THE 3 VARIABLES ## $LS_REFORMAT_PRE , $STAT_MODTIME , $DIRNAME ## on one line of output. ## ## EXAMPLE output for $FILENAME shown on end of line: ## ## 16384 drwxr-xr-x bmo01 user 2003 Sep 2 18:24:29 /apps/nns_com/fea/Dscrtest ## ########################################################################## ## To show a file name with its embedded spaces, the following works. # eval echo "$LS_REFORMAT_PRE $STAT_MODTIME \"$DIRNAME\"" ## To show a file name with its embedded spaces, this simpler form also works. echo "$LS_REFORMAT_PRE $STAT_MODTIME $DIRNAME"