Operating System - HP-UX
1753785 Members
6965 Online
108799 Solutions
New Discussion юеВ

script to copy file from several directories

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor
Solution

Re: script to copy file from several directories

>the script I use for one directory is as follows:

Change to:
find /global/xnode/mcel/tap_out -type f -exec ll -rt + |
awk '{if ($6 == "Feb" && $8 != 2010) print $9}' > file_list

scp -p $(< file_list) root@xx.xxx.xx.xx:/dcs/data02_loc/PROD/INPUT/TAPOUT/

You don't have to produce file_list if you want to go crazy and put it all on one line but you may want to keep it around with the two steps.

You can also add "-mtime -$(date +%j)" to find(1) to limit the search to just this year.
Dennis Handly
Acclaimed Contributor

Re: script to copy file from several directories

>Viktor: but you can achieve both with tar.

Don't even think of using find(1) with tar.
Unless the list is "small":
tar -cvf foo.tar $(find /Europe -newer file1 -a ! -newer file2)

# find /Europe -newer file1 -a ! -newer file2 -exec tar cvf {} \;

This puts the file in itself? :-(
Or overwrite the same tarfile you forgot.

>you can use pax if you prefer it:
# find /Europe -newer file1 -a ! -newer file2 | pax -v -w -f /tmp/myarchive

Yes.
NDO
Super Advisor

Re: script to copy file from several directories

Hi

>>Change to:
find /global/xnode/mcel/tap_out -type f -exec ll -rt + |
awk '{if ($6 == "Feb" && $8 != 2010) print $9}' > file_list



the output is:
find: incomplete statement


F.R.
Viktor Balogh
Honored Contributor

Re: script to copy file from several directories

I see that you want the hard way (ll & awk). try this:

find /global/xnode/mcel/tap_out -type f -exec ll -rt {} \+ |
awk '{if ($6 == "Feb" && $8 != 2010) print $9}' > file_list


in short: you need a {} and a + or ; at the end of -exec.
****
Unix operates with beer.
NDO
Super Advisor

Re: script to copy file from several directories



Hi

the output its empty file (file_list)

F.R.
Viktor Balogh
Honored Contributor

Re: script to copy file from several directories

>the output its empty file (file_list)

first, try without awk...
****
Unix operates with beer.
NDO
Super Advisor

Re: script to copy file from several directories

Hi

>>first, try without awk...


I dont understand.


F.R.
Viktor Balogh
Honored Contributor

Re: script to copy file from several directories

at first try only this:

# find /global/xnode/mcel/tap_out -type f -exec ll -rt {} \+

does it give any o/p?
****
Unix operates with beer.
Dennis Handly
Acclaimed Contributor

Re: script to copy file from several directories

>the output is: find: incomplete statement

This works fine on HP-UX's find(1), using a real shell. What are you using?

>Viktor: in short: you need a {} and a + or ; at the end of -exec.

On HP-UX you don't need that "{}" before the "+" but I probably shouldn't have left it out in my example.

>at first try only this. does it give any o/p?

Right. Is /global/xnode/mcel/tap_out the correct path to "Europe"? Does ll(1) produce any output?
NDO
Super Advisor

Re: script to copy file from several directories

Hi

Sorry, I was away for some days:
yes
" find /global/xnode/mcel/tap_out -type f -exec ll -rt {} \+
" does give me an output:

-rw-r--r-- 1 mcel other 123 Apr 11 08:55 /global/xnode/mcel/tap_out/BENSP/CDMOZ01BENSP02186
-rw-r--r-- 1 mcel other 123 Apr 11 08:55 /global/xnode/mcel/tap_out/NERCT/CDMOZ01NERCT01288
-rw-r--r-- 1 mcel other 123 Apr 11 08:55 /global/xnode/mcel/tap_out/ARGCM/CDMOZ01ARGCM01811
-rw-r--r-- 1 mcel other 123 Apr 11 08:55 /global/xnode/mcel/tap_out/ALBAM/CDMOZ01ALBAM01766


F.R.