Unix Shell - Copy modified files from one directory to another.

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > Copy modified files from one directory to another.





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Copy modified files from one directory to another.
mizwam

2007-02-07, 7:22 pm

Hi,

Two directories with same content exist on the unix box. Some of the
content of one directory keeps on changing over time. I have to write
a shell script to update the other directory with the changes. Problem
is to copy only the changed/modified files to the other directory
(maintaining the directory structure). How can this be achieved using
simple shell script?

Thanks,

Bill Marcum

2007-02-07, 7:22 pm

On 7 Feb 2007 15:16:16 -0800, mizwam
<mail.manasi.sharma@gmail.com> wrote:
>
>
> Hi,
>
> Two directories with same content exist on the unix box. Some of the
> content of one directory keeps on changing over time. I have to write
> a shell script to update the other directory with the changes. Problem
> is to copy only the changed/modified files to the other directory
> (maintaining the directory structure). How can this be achieved using
> simple shell script?
>

rsync


--
Nothing is so often irretrievably missed as a daily opportunity.
-- Ebner-Eschenbach
mizwam

2007-02-08, 1:29 am

On Feb 7, 6:32 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 7 Feb 2007 15:16:16 -0800, mizwam <mail.manasi.sha...@gmail.com> wrote:
>
>
>
> rsync
>
> --
> Nothing is so often irretrievably missed as a daily opportunity.
> -- Ebner-Eschenbach



Thanks Bill but I am not allowed to install any new utility (like
rsync) on the unix box. I was looking for a more basic way - maybe
iterating through the directories and comparing the contents etc.

Bo Yang

2007-02-08, 1:29 am

mizwam :
> On Feb 7, 6:32 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
>
> Thanks Bill but I am not allowed to install any new utility (like
> rsync) on the unix box. I was looking for a more basic way - maybe
> iterating through the directories and comparing the contents etc.

Then you are reinventing another rsync.
You can install your rsync in your own home dir, I think nobody will
constrain you from doing that!
swami

2007-02-08, 1:29 am

here is the solution:
let us consider A contains additional files than B.
1) Get the last modfied timestamp from B
2) find the newer files in A using the command
find -newer [last_modified_timestamp]
3) Copy those files

all these can be achieved through simple 3 line shell script.
Please let me know if you need more details.
Thanks,
Siva

On Feb 8, 10:23 am, Bo Yang <strug...@mail.nankai.edu.cn> wrote:
> mizwam :
>
>
>
>
>
> Then you are reinventing another rsync.
> You can install your rsync in your own home dir, I think nobody will
> constrain you from doing that!



mizwam

2007-02-08, 7:20 pm

On Feb 8, 2:21 am, "swami" <sivaswamim...@gmail.com> wrote:
> here is the solution:
> let us consider A contains additionalfilesthan B.
> 1) Get the last modfied timestamp from B
> 2) find the newerfilesin A using the command
> find -newer [last_modified_timestamp]
> 3)Copythosefiles
>
> all these can be achieved through simple 3 line shell script.
> Please let me know if you need more details.
> Thanks,
> Siva
>


Thanks Siva, this won't work since both the directories A and B are
checked out from different Configuration management systems (Synergy
CM and PVCS), and my aim to make sure that both are in sync. As soon
as i check out - the time of checking out becomes the time of
modification. What i am looking for is a way to compare the content in
the files. Check out from PVCS store in directory A and Checkout from
Synergy CM stored in directory B. Copy A to B - copy only those files
that have changed. Any ideas?


swami

2007-02-09, 1:17 pm

In this case, The following options can help you

1) You can check out to specific directories created by you by the
script.
and you can easily migrate the files within that directory.

for eg:

A /My <----------- checked out files
cp A/My B
cp A /My A

Similarly this can be done for the B Directory

2) You can get the Listing of directory through ls -l > List
after the directory has been updated you can compare the directory
Structure with the List file.
if the file is newer you can copy the file to the B directory.

3) You can use the access time of the files. but care must be taken
that no ls -l is performed on the directory.



On Feb 9, 1:13 am, "mizwam" <mail.manasi.sha...@gmail.com> wrote:
> On Feb 8, 2:21 am, "swami" <sivaswamim...@gmail.com> wrote:
>
>
>
> Thanks Siva, this won't work since both the directories A and B are
> checked out from different Configuration management systems (Synergy
> CM and PVCS), and my aim to make sure that both are in sync. As soon
> as i check out - the time of checking out becomes the time of
> modification. What i am looking for is a way to compare the content in
> the files. Check out from PVCS store in directory A and Checkout from
> Synergy CM stored in directory B. Copy A to B - copy only those files
> that have changed. Any ideas?



Rich Grise

2007-02-14, 7:21 pm

On Wed, 07 Feb 2007 15:16:16 -0800, mizwam wrote:

> Hi,
>
> Two directories with same content exist on the unix box. Some of the
> content of one directory keeps on changing over time. I have to write a
> shell script to update the other directory with the changes. Problem is to
> copy only the changed/modified files to the other directory (maintaining
> the directory structure). How can this be achieved using simple shell
> script?



#mind the line wrap:

user@ops:~
$ crontab -l
0 0 * * * date >> /pub/home/user/Log/cron.log ; cp -Ruxv /NewServer/* /home/user/Server >> /pub/home/user/Log/cron.log
user@ops:~
$

Cheers!
Rich

mizwam

2007-02-19, 1:16 pm

On Feb 14, 6:13 pm, Rich Grise <r...@example.net> wrote:
> On Wed, 07 Feb 2007 15:16:16 -0800, mizwam wrote:
>
>
> #mind the line wrap:
>
> user@ops:~
> $ crontab -l
> 0 0 * * * date >> /pub/home/user/Log/cron.log ; cp -Ruxv /NewServer/* /home/user/Server >> /pub/home/user/Log/cron.log
> user@ops:~
> $
>
> Cheers!
> Rich


Hi Rich,

Can you explain to me the code that you have written. I couldn't
understand it at all - i am new to unix shell.

Thanks,

Bit Twister

2007-02-19, 7:15 pm

On 19 Feb 2007 09:51:58 -0800, mizwam wrote:

> Can you explain to me the code that you have written. I couldn't
> understand it at all - i am new to unix shell.


Append date/time to bottom of /pub/home/user/Log/cron.log with
date >> /pub/home/user/Log/cron.log
do a
man cp
to understand the rest of the script.

Some light reading found at
http://tldp.org/LDP/abs/html/index.html
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com