#!/bin/ksh ## ## SCRIPT: file_ls_stat_info ## ## Where: in $FEDIR/scripts where $FEDIR=/apps/nns_com/fea ## ############################################################################## ## PURPOSE: This script is used to get the 'ls -l' info for a file, 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 'diruse_files_all_levs_agesort_bygui' ## in $FEDIR/scripts ## and perhaps eventually in other utility scripts. ############################################################################## ## INPUT: a filename, preferably fully-qualified. ## ## NOTE: The input filename is typically coming from a 'find' ## command like the example shown in the 'FOR TESTING' ## section below. ############################################################################## ## OUTPUT: a file-info, echoed to 'standard out'. ############################################################################## ## FOR TESTING: : Can paste the following at a shell-command prompt: ## ## find -local -type f \ ## -exec /apps/nns_com/fea/scripts/file_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 28apr2003 ## Updated by: Blaise Montandon 28apr2003 ############################################################################### FILENAME="$1" if test "$FILENAME" = "" then echo " Script $0 needs a filename --- preferably fully-qualified, like intended input from 'find' '{}' symbol for a given fully-qualified directory name. Exiting ... " exit fi ########################################################################### ## GET ALL 'ls -l' output for the file. ## EXAMPLE: ## -rw-r--r-- 1 bmo01 user 27 Apr 25 10:31 /apps/nns_com/fea/Dscrtest/test_ls_stat ## ########################################################################### ## FOR TESTING: (TURN THIS OFF WHEN THROUGH TESTING!!) # set -x # LS_OUT=`ls -l "$FILENAME"` LS_OUT=`ls -l "$FILENAME" 2> /dev/null` ########################################################################## ## GET 'modify time' 'stat' output for the file. ## EXAMPLE: ## modify time - Mon Mar 10 16:13:14 2003 <1047330794> ## of ## inode 29463069; dev 1310721; links 1; size 41688 ## regular; mode is rw-r--r--; uid 2250 (bmo01); gid 20 (user) ## projid 0 st_fstype: nfs ## change time - Mon Mar 10 16:13:14 2003 <1047330794> ## access time - Fri Apr 25 09:41:05 2003 <1051278065> ## modify time - Mon Mar 10 16:13:14 2003 <1047330794> ## ########################################################################## STAT_MODTIME=`stat "$FILENAME" 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: ## 27 -rw-r--r--bmo01 user ## of ## -rw-r--r-- 1 bmo01 user 27 Apr 25 10:31 /apps/nns_com/fea/Dscrtest/test_ls_stat ## ########################################################################## LS_REFORMAT_PRE=`echo "$LS_OUT" | awk '{print $5 " " $1 " " $3 " " $4}'` ########################################################################## ## PUT TOGETHER THE 3 VARIABLES ## $LS_REFORMAT_PRE , $STAT_MODTIME , $FILENAME ## on one line of output. ## ## EXAMPLE output for $FILENAME shown on end of line: ## ## 41688 -rw-r--r-- bmo01 user 2003 Mar 10 16:13:14 /usr/people/bmo01/.profile ## ## 1891 -rwxr-xr-x bmo01 user 2003 Apr 25 10:54:36 ./test_file_ls_stat_info ## ## 1901 -rwxr-xr-x bmo01 user 2003 Apr 25 11:06:23 test_file_ls_stat_info ## ########################################################################## ## To show a file name with its embedded spaces, the following works. # eval echo "$LS_REFORMAT_PRE $STAT_MODTIME \"$FILENAME\"" ## To show a file name with its embedded spaces, this simpler form also works. echo "$LS_REFORMAT_PRE $STAT_MODTIME $FILENAME"