Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-17-2011, 03:52 AM   #1
LQ Newbie
Registered: Dec 2006
Posts: 2

Rep: Reputation: 0
Please help me write shell script to check the modified date of a file.

Dear all,

I have two linux servers, they are backup together.

1. Server 1 have 3 files with name: file1, file2, file3 in the path: /etc/sysconfig/network-script/.
2. Server 2 have 3 files with name and path are the same as server 1.

- Please help to make a script to copy 3 files at server1 to overwrite on server2. But before overwrite, this script will check and compare the last modified date of these 3 files(on server1 and server2). if the modified date of file1, file2 or file3 on server1 is newer than 3 files on server2 then overwrite process will do, if not, will do nothing.
- Please see my script as below: it works find now but just overwrite. not check last modified date.

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin


echo $.\n\n. >> $LOGFILE
echo "Completed at: `/bin/date`" >> $LOGFILE

Thanks and regards,
Old 06-17-2011, 04:14 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,348

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363

The rsync should take care of this. You could use -v multiple times to get more verbose logging. Twice will show if the files are up to date, three times will show system calls used.


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
How to write a shell script which will check a file name in a dir and copy it siris Programming 3 04-08-2010 07:54 PM
shell script that adds users name to a file when the file is modified netting4u Linux - General 1 03-30-2010 04:09 AM
Need to write a shell script which will check the GUI login and retuen the status cod bhsk_08 Linux - General 2 10-14-2008 01:08 PM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:43 PM.

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