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
How to find the create time of a file if current date is in next month priyankak Shell Programming and Scripting 1 05-18-2009 04:19 AM
Prefix the current date and time to the output of ps Bloke Shell Programming and Scripting 2 04-08-2009 08:25 AM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 04:32 AM
param as current date+time itik Shell Programming and Scripting 1 06-13-2008 04:25 PM
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM

Reply
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 06-03-2009
Bill Ma Bill Ma is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
compare file modification date/time to current date/time

How do I compare the file modification date/time to the current system date/time? I need this to check to see if a new file is being ftp'ed every hour/every 6 hours, etc.

Thanks in advance.
  #2 (permalink)  
Old 06-03-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
#!/bin/ksh
# filetimes.sh
# usage  filtimes.sh [filename]
filetime()
{
    perl  -e '
          $mtime = (stat $ARGV[0])[9];
          print $mtime
         ' $1
}
now=$(date +%s)
limit=$(( $now - 21600  ))  # 6 hours ago
ftime=$(filetime $1 )
if [[ $ftime -lt $limit ]] ; then
   echo "file too old"
fi
  #3 (permalink)  
Old 06-03-2009
Bill Ma Bill Ma is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
got this syntax error

Thanks for the quick response. I ran this and received the following error:

%s - 21400 : syntax error
  #4 (permalink)  
Old 06-03-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 519
Quote:
Originally Posted by Bill Ma View Post
...I need this to check to see if a new file is being ftp'ed every hour/every 6 hours, etc.
...
Not sure, but maybe this could help:

Code:
find . -type f -mmin -360
lists down all regular files in the current directory whose data was last modified less than 360 minutes (6 hours) ago.

tyler_durden
  #5 (permalink)  
Old 06-04-2009
Bill Ma Bill Ma is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 5
find options

unfortunately the Unix find command installed does not have the mmin option only the mtime option which (to my knowledge) only accepts integer values -- days -- not hours
  #6 (permalink)  
Old 08-27-2009
Llanferres Llanferres is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 1
syntax error

Try:

now=`date '+%s'`
(( limit=$now-21600 )) # 6 hours ago
Reply

Bookmarks

Tags
modification date, unix

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:11 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