LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 05-24-2013, 05:02 AM   #1
errgrdgds
LQ Newbie
 
Registered: May 2013
Posts: 4

Rep: Reputation: Disabled
[bash] Copy files, move files but not added ones


Hello,
I have to write a bash script to take XML files in directory x, copy them to directory y and then move the same set of files to directory z.

The script itself isn't a problem, except that there will be users uploading XML files into directory x constantly. So I need to in effect take a 'snapshot' of the files that are in there when the script is run.. copy them to y and then move them to z, ignoring any that are added between the time the cp is effected, and the mv.

I'm guessing that this involves doing a find, firing the result into a file, and then reading from that file, but this is something I've never done before.

Can someone advise? Oh, and no- this isn't a 'homework' exercise. It's for my work. Thanks.
 
Old 05-24-2013, 05:13 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
That's what rsync does. Yes, it works on local files too:
Code:
rsync /path/    /topath1/
rsync /topath1/ /topath2/
Oops, sorry, I missed the move (=delete) part...

Last edited by NevemTeve; 05-24-2013 at 05:18 AM.
 
Old 05-24-2013, 05:23 AM   #3
errgrdgds
LQ Newbie
 
Registered: May 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
That's what rsync does. Yes, it works on local files too:
Code:
rsync /path/    /topath1/
rsync /topath1/ /topath2/
Oops, sorry, I missed the move (=delete) part...
Ah, yes... rsync, I hadn't thought of that! That *would* work, but how do I stop the subsequent mv from treating files that weren't there when the rsync ran?

I go to check the manpage...
 
Old 05-24-2013, 06:36 AM   #4
errgrdgds
LQ Newbie
 
Registered: May 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
That's what rsync does. Yes, it works on local files too:
Code:
rsync /path/    /topath1/
rsync /topath1/ /topath2/
Oops, sorry, I missed the move (=delete) part...
Now, here's something intriguing..

Code:
/bin/ls $startDir/*.xml | sed 's!.*/!!' > $listOfFiles

$rsyncExec -ax --files-from $listOfFiles $startDir $endDir0

$rsyncExec -ax --files-from $listOfFiles $startDir $endDir1
The first rsync works perfectly: I inserted a temporary `exit 0` in there, and checked $endDir0.

When it comes time to run the second rsync, I get..

Code:
rsync: mkstemp "/path_to_file/.1.xml.5yz6bY" failed: No such file or directory (2)
rsync: mkstemp "/path_to_file/.2.xml.Z8gDGe" failed: No such file or directory (2)
rsync: mkstemp "/path_to_file/3.xml.5Dnabv" failed: No such file or directory (2)
rsync: mkstemp "/path_to_file/.4.xml.62AHFL" failed: No such file or directory (2)
rsync: mkstemp "/path_to_file/.5.xml.vjXea2" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
Any idea what I've done wrong?

Thanks.
 
Old 05-24-2013, 06:46 AM   #5
errgrdgds
LQ Newbie
 
Registered: May 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
I think the second one is failing because it's trying to copy to a directory which in fact is mounted from an NFS server. The first directory isn't.

Looks like I have to use ol' `mv` or even `cp` followed by `rm`..
 
  


Reply



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
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
How to copy/move files and skip... Skillz Linux - General 15 09-28-2009 09:58 AM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM
Bash: keeping track of newly added files madtinkerer Programming 5 09-13-2006 09:30 AM
how to move and copy files.... JMK Linux - Newbie 3 01-22-2004 04:57 PM

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

All times are GMT -5. The time now is 04:17 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
Open Source Consulting | Domain Registration