Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Help. noob needs help with file copy!
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 07-17-2008   #11 (permalink)
Bigtomrodinator
 
bigtomrodney's Avatar
 
Join Date: Nov 2004
Location: Sunny South-East of Ireland
Posts: 5,194
Quote:
Originally Posted by wje_lf View Post
Two nits, one unimportant, one important.

The unimportant one: By "created", I assume you mean "most recently modified", correct?

The important one: By "millisecond", I hope you mean "second".
On the first one, I meant modified. Absolutely got me there!

On the second one I was about to say that rsync actually works in bundles of 3 milliseconds. Then the penny dropped how silly that sounded and I remembered that I was actually thinking of was the database I use at work.

So I've been busily off looking for a reference to anything close to it, and best I have come up with was a reference to filesystem timestamp resolution in the man page for rsync, and that ext4 has nanonsecond timestamps, to improve on ext3. I've tried getting that for ext3 but so far I've seen everything from seconds to milliseconds so I can't be certain there.

Anyway, if any of that has cast any aspersions on potential fixes I'm sorry
__________________
Registered Linux user #378740
New members read here / Forum Rules
#linuxforums on irc.freenode.net
bigtomrodney is offline   Reply With Quote
Old 07-17-2008   #12 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,019
Quoth wildside:
Code:
I get this:
<snip>
If that's all you get in the output script, then it looks like the script you ran includes only the first of these lines, not the second:
Code:
        echo echo cp -p "$f" "$destfile" >> copyscript.sh
        echo cp -p \"$f\" \"$destfile\" >> copyscript.sh
The script should contain both of those lines. Could that be the problem?
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 07-17-2008   #13 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,019
Quote:
I'm sorry
Nah. By now this thread is going in a different direction anyway.

What I'm wondering, and maybe if you know C you can help out, or someone else can jump in: If the time of most recent modification is less granular (more precise) than one second, how does a C program pick up on that? The stat() function doesn't go more precise than a second.
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 07-18-2008   #14 (permalink)
Just Joined!
 
Join Date: Jun 2008
Posts: 22
Quote:
I know that my script is NOT determining if the file is newer or not correctly. It thinks that even though it is the same exact mod date that it is newer so it skips it. I belive my error is here:

Code:

if find "$destfile" -newer "$f"

But i dont know what else to add to the switches to make it work.
I thought of maybe using -newerXY

I need it to copy the file as long as it exists with the same date and only skip if the dest file is newer.

Any thoughts?
Yes, the problem is in the IF statement. It would have worked if the exit value($?) for the find -newer return non-zero value when $destfile is newer than $f. Unfortunately this is not the case. The exit value is always zero and that's why the statement in THEN is always executed.
So to make it work, test the output string from find instead of its exit value. On way of doing it is replace the IF statement with :
Code:
if [ `find "$destfile" -newer "$f"` ]
-Steve
Steve Yau is offline   Reply With Quote
Old 07-18-2008   #15 (permalink)
Linux User
 
Join Date: Aug 2006
Posts: 353
Quote:
Originally Posted by wildside View Post
I need to copy files from FolderA into FolderB replacing all files that already exist in FolderB UNLESS the date of the file in FolderB is newer than the date from the same file in FolderA. In the case that file is newer in the destination, I need to skip copy of that file and move on.
the cp command should have a -u switch. It copies when source is newer than destination. Is that what you want.?
ghostdog74 is offline   Reply With Quote
Old 07-18-2008   #16 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,019
He wants not "newer", but "newer or equal". That's the sticking point.
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 07-18-2008   #17 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 20
Quote:
Originally Posted by wje_lf View Post
He wants not "newer", but "newer or equal". That's the sticking point.
Yes. Exactly. that is what seems to be hanging most everyone up on this issue. Seems so trivial.
wildside is offline   Reply With Quote
Old 07-18-2008   #18 (permalink)
Linux Engineer
 
wje_lf's Avatar
 
Join Date: Sep 2007
Location: Mariposa
Posts: 1,019
Ok, here's whatcha do:
  1. Copy all the files which are newer on FolderA. What remains is to copy all the files whose date and time of most recent modification is the same on both FolderA and FolderB.
  2. Run this script, which I have not tested:
    Code:
    #!/bin/bash
    (cd /FolderA; find . | xargs stat -c "%y|%n") > astats.txt
    (cd /FolderB; find . | xargs stat -c "%y|%n") > bstats.txt
    sort astats.txt bstats.txt | uniq -d | sed -e 's/^.*|/cp \/FolderA\//' -e 's/$/ \/FolderB/' > copysametime.sh
    
  3. Inspect the file copysametime.sh for accuracy. It should contain copy commands for only those files whose time of most recent modification is identical for both folders.
  4. Run that sucker, after changing permissions so you can do so.
This work for you?
__________________
--
Bill

Old age and treachery will overcome youth and skill.
wje_lf is offline   Reply With Quote
Old 07-18-2008   #19 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 20
Ok. gonna give this a shot. Much different approch than before. Hope this works.
Thanks for all the help on this.
wildside is offline   Reply With Quote
Old 07-18-2008   #20 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 20
What is the switch -c? I get this error when i run it on my macbookpro:

Code:
wildside@wildsides-MacBook-Pro / $ ./copytest4
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
i can look for the same option in my man page but i just need to know what the -c is supposed to do.

thanks
wildside is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off
 

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 02:15 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0