LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2004, 11:44 AM   #1
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Rep: Reputation: 15
File Modification Date Comparison


I'm not a programmer by trade but have a decent understanding and ability to follow code. I'm using RedHat 9 and wanted to be able to check the modification date and compare it to the current date to insure that backups have been completed properly. ie a directory is tarred and gzipped and then put into a backups directory. Then I want to go through each file sequentially in the backups directory and make sure each was created or modified on the current date. Hope this makes sense! I'd also like to do with with bash scripting because it'll be easiest for me to understand and I think implement. Thanks!
 
Old 01-29-2004, 11:48 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
find -mtime will list files older (or newer) than a certain time.

check the man page for find.
 
Old 01-29-2004, 11:52 AM   #3
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Original Poster
Rep: Reputation: 15
Yeah. I was looking at that. I guess that would help me to find out if ANY of the files failed. But I'd like to be able to adapt whatever I get here to identify the file and the re-attempt the backup. Though, I guess I could use some sort of string monipulation to isolate the names of the files from what's returned... But I think I'd get stuck again after that anyways! And it seems a bit like a hack job to have to search through a string like that :S

I know that 'date -r $filename + %e' will return the date. Which I can then compare to 'date +%e'. But that only goes for one file at a time :S How can I get $filename to be replaced sequentially with each file in the directory?

Last edited by MadTurki; 01-29-2004 at 11:55 AM.
 
Old 01-29-2004, 03:13 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Code:
for filename in /directory1/subdirectory/*
do 
     # play with $filename
done
 
Old 03-08-2004, 11:23 AM   #5
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Original Poster
Rep: Reputation: 15
I cant get this to work right. Right now I have (I know this is wrong btw and I've tried variations):

for filename in /home/whatever/*; do
if [ date -r $filename +%e ] = [ date +%e ]; then
echo "success"
else
echo "failure"
fi
done

This is returning the error:
./dateCheck.sh: line 2: [: missing ']'

I've tried other things with quotes and still gotten errors. What I'm trying to do is examine the modification date of all the files in a directory one at a time, and compare them with the current date. If they're the same, I want a success message printed and if different then an error message. Thanks for your help
 
Old 03-08-2004, 01:46 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
syntax problem:
Code:
a=`date -r $filename +%e`
now=`date +%e`
if [ "$a" = "$now" ]; then
   # do stuff
fi
 
Old 03-08-2004, 02:00 PM   #7
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Original Poster
Rep: Reputation: 15
Beeeeeaaauty! Thank you so much. Works perfectly

Actually - It doesnt... They all get reported as failed even if the dates should match! I did an "echo $a" and an "echo $now" during the run and it only out put "date -r $filename +%e" and "date +%e" respectively. Not quite what I was hoping! Why isnt it processing that before it's put into the variable?

Last edited by MadTurki; 03-09-2004 at 11:54 AM.
 
Old 03-08-2004, 04:02 PM   #8
MadTurki
Member
 
Registered: Nov 2003
Location: Toronto
Distribution: RedHat 9, Mandrake 10, OS X
Posts: 114

Original Poster
Rep: Reputation: 15
Sorry - now what if I wanted to make this search the subdirectory which corresponds to the current day?

current='date +%a'
cd $current

a=`date -r $filename +%e`
now=`date +%e`
if [ "$a" = "$now" ]; then
# do stuff
fi

That way no matter when I run this script it'll go into the right directory and check the files. Thanks for your help. I'm sure this is just another simple problem but I cant find a solution in my book.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
file modification in linux nov Linux - Newbie 3 06-05-2005 09:02 AM
Heeelp! How to preserve file date modification attribute Slackovado Slackware 1 03-30-2005 09:36 AM
New Samba date modification problem mdkelly069 Linux - Networking 14 01-12-2004 11:42 AM
Help with Samba and date modification mdkelly069 Linux - Networking 6 11-28-2003 06:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration