The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare date from db2 table to yesterday's Unix system date sasaliasim Shell Programming and Scripting 9 12-01-2008 11:37 PM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
date issue-find prevoius date in a patricular format bsandeep_80 UNIX for Advanced & Expert Users 3 11-15-2007 08:42 PM
Changing Creation Date to a Prespecified Date of a File In Unix monkfan UNIX for Dummies Questions & Answers 4 11-28-2006 07:15 AM
a simple way of converting a date in seconds to normal date travian HP-UX 2 11-23-2006 12:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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.
  #2 (permalink)  
Old 08-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
pls for the future..... use VBcodes to properly format your posting - you can click on the on the bottom left of the window "Posting rules" to get the details of the VB codes

this reassigns the value of 'filedate' to a variable 'date'

Code:
date=$filedate
this assigns the return value of the command 'date' to a variable 'fdate'
Code:
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?)
The code behaves as implemented. I think you're having something else in mind.
  #3 (permalink)  
Old 08-02-2005
radhika radhika is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 51
In the following command (fdate=`$filedate +%Y%m%d%H%M%S`
) if I put the filedate I get the below error. That's why I was trying to do date=$filedate

Output............................
fdate1:
filesize is: 0
fdate is empty or fdate has spaces
Jul 21 00:54
perf_totals.sh[33]: Jul: not found (errror...........)
date time when file was created is:
  #4 (permalink)  
Old 08-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
let me ask you:
what is the difference between 'filedate' and 'fdate'?
  #5 (permalink)  
Old 08-02-2005
radhika radhika is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 51
fdate- if a data file is created with actual data then first 14 chars of the data file will have the datetime stamp(14char format) in the data file for each record.

If an empty data file is created then file size is 0. With the help of file size I am trying to get the date time stamp of when the empty file was created. This is filedate. Requirement is to put this stamp in another control file. This
  #6 (permalink)  
Old 08-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
I think you need to revisit your logic and reconcile your description with what's been coded.

Again....
Code:
# assigns the value of the variable 'filedate' to the variable 'date'
date=$filedate

# assigns CURRENT time to the variable 'fdate'
fdate=`date +%Y%m%d%H%M%S`
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0