The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-02-2005
radhika radhika is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 51
date is not getting the filedate value.

I have the following script. I am trying to get the date time when an empty file was created. In my situation if an empty file is created it won't be touched again. At the end of the script I state the problem- the
#!/bin/ksh
#Source the file
. $HOME/.profile
typeset -L100 fname
typeset -L14 fdate
typeset -R12 reccnt
typeset -R12 charcntfinal
typeset -R12 cnt1
typeset -R12 cnt2
typeset -R12 sum1

fname=$1

#Get the actual date when the file was created, clip it from the actual data file.
fdate=`cut -c1-14 $fname`
echo fdate1: $fdate

#Get file size.
filesize=`ls -lrt $fname | awk '{ print $5 }'`
echo filesize is: $filesize

#Checks to see if variable is empty or if file size is 0.
if [[ -z $fdate ]] || [ $filesize = "0" ]
then
echo fdate is empty or fdate file size is 0.
#Get the date and time when the empty file was created.
#get the date time value from the ls -al output, where the delimiter is the file size (which is 0)
filedate=`ls -al $fname | cut -f2-4 -d'0' | cut -f1-4 -d' ' `
echo fdate when file was created is: $filedate
date=$filedate
fdate=`date +%Y%m%d%H%M%S` (#PROBLEM? here date is not getting $filedate value. It still picks up the current date value. Don't know why?)
echo date time when file was created is: $fdate
fi

"perf_totals.sh" 73 lines, 2429 characters
ussun0s/scripts>

#Running the script..............................
ussun0s/scripts> perf_totals.sh gsk_vac.txt gsk_vac_control.txt
fdate1:
filesize is: 0
fdate is empty or fdate has spaces
fdate when file was created is: Jul 21 00:54
date time when file was created is: 20050802142511 (this is the problem. I am still getting the current date here, rather than the fdate when file was created.)

Any help is greatly appreciated.
Regards,
Radhika.