Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Complicated file copy issue...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Hoshimaru
Apprentice
Apprentice


Joined: 09 Nov 2003
Posts: 225
Location: Belgium

PostPosted: Sun Nov 07, 2004 10:43 am    Post subject: Complicated file copy issue... Reply with quote

Hi,

This is kind of complicated. I received a patch "patch" for a dedicated server. However, that patch contains all updates and not only the last one.

I managed to find out what the new file were, doing
Code:
find Files/ -mtime 2 > new.txt


That new.txt looks like this:
Code:
Files/bin/dedicated.dll
Files/bin/dedicated_amd.so
Files/bin/dedicated_i486.so
Files/bin/dedicated_i686.so
Files/bin/engine_amd.so
Files/bin/engine_i486.so
Files/bin/engine_i686.so
Files/bin/tier0_i486.so
...


How can I copy all the files mentionned in that file to another location, like ~/patch5/ and regenerate the directory tree as well ?
Back to top
View user's profile Send private message
Hoshimaru
Apprentice
Apprentice


Joined: 09 Nov 2003
Posts: 225
Location: Belgium

PostPosted: Mon Nov 08, 2004 5:21 pm    Post subject: Reply with quote

I tried this...
Code:
# cp -Rv `cat new.txt` target/

it copies the right files, but it doesn't regenerate the directories on target.
Files/bin/file1.bin become target/file1.bin
That's not what I'm looking for :'(
Back to top
View user's profile Send private message
abcdefg
Apprentice
Apprentice


Joined: 29 Feb 2004
Posts: 216
Location: The Netherlands

PostPosted: Mon Nov 08, 2004 9:19 pm    Post subject: Reply with quote

There probably a faster way, but his was some good bash practise for me :)

Code:
from=/home/user/location
to=/home/user/another_location
files=$(find $from/ -mtime 2)


for X in $files
do
Y=$(dirname $(echo "$X" | sed "s:$from::g"))
mkdir -p $to/$Y
cp $X $to/$Y
done


I think this should work, place this text in a file and make it executable (chmod +x file) of course modify the from and to locations.
Back to top
View user's profile Send private message
Hoshimaru
Apprentice
Apprentice


Joined: 09 Nov 2003
Posts: 225
Location: Belgium

PostPosted: Thu Nov 11, 2004 10:01 am    Post subject: Reply with quote

Hi, thanks for your script :)

I almost works. It's having trouble with directories containing blanks. It forgets the part after the blank.

I'm looking how I can add
Code:
sed s/a/'\\\ '/g
to your script.

It's a long time ago since I did shell scripts and almost forget everything :s


Last edited by Hoshimaru on Fri Nov 12, 2004 7:40 am; edited 1 time in total
Back to top
View user's profile Send private message
abcdefg
Apprentice
Apprentice


Joined: 29 Feb 2004
Posts: 216
Location: The Netherlands

PostPosted: Thu Nov 11, 2004 9:42 pm    Post subject: Reply with quote

I have no idee how to solve that problem. Currently it puts all the files that must be copied in a variable seperated by spaces, like: "/home/user/file1 /home/user/file with spaces /home/ etcetc" The problem is that is sees a file with spaces like two (or more) different files. Which of course isn't correct...

Does somebody else know how to solve this problem?
Back to top
View user's profile Send private message
karatefish
n00b
n00b


Joined: 27 Oct 2004
Posts: 34
Location: Singapore

PostPosted: Fri Nov 12, 2004 3:33 am    Post subject: Reply with quote

what about using the tar method from here? tar preserves directory structures in usual use, I can't see why it wouldn't work in this case....

edit: I just did a quick test and it seems to work fine. The command I guess would be something like:
Code:
 tar -cf - `cat new.txt` | tar -C ~/patch5/ -xvf -

assuming you've already created the ~/patch5 directory of course...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum