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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculate the date of next satureday of current date. rinku Shell Programming and Scripting 3 09-02-2008 11:05 PM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 04:32 AM
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
check the current date file in directory pallvi SUN Solaris 2 01-04-2008 05:57 PM
how to give current date in file name? simurg11 UNIX for Dummies Questions & Answers 3 05-10-2005 09:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-04-2007
trexlim trexlim is offline
Registered User
  
 

Join Date: May 2007
Posts: 1
File date vs Current date

I am a newbie in shell scripting, hope you can advice how can I compare the date/time of file extracted from 'll' and current system date/time.

I have done the following:

ll -rt > $FILE_AGE_LOG
FILE_DATETIME=`more $FILE_AGE_LOG | head -02 | cut -c 45-57`

It returns 'May 4 19:11'.

If I want to put in a condition to check if the file is more than 15 minutes old, something like the following.

if [ $FILE_DATETIME < (`date`-15) ]

Please kindly advice how can I do that?
Thanks.
  #2 (permalink)  
Old 05-04-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Trexlim,
A true date calculation can be very involved as you have to consider leap years.
One way to solve your problem is:
1) One time only, create a "15_minutes_file".
2) Create a cron job that runs every 15 minutes.
2.a) Test if the file is older than 15_minutes_file -- "if file -ot 15_minutes_file"
2.a.I) Meets your criteria.
2.b) Update (touch) the "15_minutes_file" file with the current date.
See if this works for you.
  #3 (permalink)  
Old 05-04-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
try something like this:
Code:
#!/bin/ksh
# tdiff.sh 


tdiff()
{
perl -e '
   ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
   $atime,$mtime,$ctime,$blksize,$blocks) = stat("$ARGV[0]");
   $difference = time - $mtime;
   print $difference;
   ' "$1"
}

secs=$(tdiff "$1")
minutes=$secs/60
if [[ $minutes -le 15 ]] ; then
    echo "$1 is 15 minutes old or less"
else
    echo "$1 is older than 15 minutes"    
fi
  #4 (permalink)  
Old 05-04-2007
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 439
Following on with Shell Life

You could after touching the 'timestamp' file, do
'ls -ltr' and see what files are listed after the datestamp file.
Note that the granularity of the list may only be to the nearest minute.
  #5 (permalink)  
Old 05-04-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
get a file date/timestamp
Sponsored Links
Closed Thread

Bookmarks

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 08:35 PM.


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