LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-17-2011, 04:52 AM   #1
thinhnguyenduy79
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.

#!/bin/sh
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

SOURCEPATH='/etc/sysconfig/network-scripts/test_sync
/etc/sysconfig/network-scripts/test_sync1
/etc/sysconfig/network-scripts/test_sync2'

DESTPATH='/etc/sysconfig/network-scripts/'
DESTHOST='192.168.9.25'
DESTUSER='root'
LOGFILE='rsync.log'
echo $.\n\n. >> $LOGFILE
rsync -av --rsh=ssh $SOURCEPATH $DESTUSER@$DESTHOST:$DESTPATH 2>&1 >> $LOGFILE
echo "Completed at: `/bin/date`" >> $LOGFILE

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

Rep: Reputation: 297Reputation: 297Reputation: 297
Hi

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.
 
  


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


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration