Operating System - HP-UX
1826780 Members
1564 Online
109702 Solutions
New Discussion

script to copy file from several directories

 
SOLVED
Go to solution
NDO
Super Advisor

Re: script to copy file from several directories

Hi Viktor!

I did not pursue your went for your suggestion because I did not understand it very well, but I am going to try, for March . But your Europe directory needs to be replaced by /global/xnode/mcel/tap_out path?



>>First, I would create two marker files. >>file1 should have a timestamp of february >>1st, file2 february 28.

>># touch -t 201102010000 file1
>># touch -t 201102282359 file2

>>With these two, the following find command >>will result in all the files you need to >>copy:

>># find /Europe -newer file1 -a ! -newer >>file2 -print

>>With this, you can generate a file list, >>tar it and scp it. I'm not sure if you >>want to copy these with full path or not, >>but you can achieve both with tar.

>>you can use the exec option of find:

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

>>or you can use pax if you prefer it:

>># find /Europe -newer file1 -a ! -newer >>file2 | pax -v -w -f /tmp/myarchive

>>Regards,
Viktor Balogh
Honored Contributor

Re: script to copy file from several directories

> I did not pursue your went for your suggestion because I did not understand it very wel

basically you create two files, one with a timestamp for the beginning of the month and one for the end of the month. You do this with the -t option of touch:

# touch -t 201102010000 file1
# touch -t 201102282359 file2

after this, you can search for files what are newer than file1 but older than file two - practically these are the files from the whole month. Once you understand this, you can search for files with any timestamp on your system.

# find /Europe -newer file1 -a ! -newer file2 -print

and yes, in my example /Europe was only a "testdir", I don't know your environment so couldn't supply a solution which fits your system.
****
Unix operates with beer.
NDO
Super Advisor

Re: script to copy file from several directories


Hi Viktor

I am going to do it for march them I let you know


Steven Schweda
Honored Contributor

Re: script to copy file from several directories

> # touch -t 201102010000 file1
> # touch -t 201102282359 file2

I'm more accustomed to VMS, where /BEFORE
really means "earlier than" and /SINCE means
"equal to or later than", so I know nothing,
but if one doesn't wish to leave a hole at
midnight, then shouldn't those be either:

# touch -t 201102010000 file1
# touch -t 201103010000 file2

(if "-newer" really means "as new as") or
else:

# touch -t 201101312359 file1
# touch -t 201102282359 file2

(if "-newer" really means "newer than")?
Dennis Handly
Acclaimed Contributor

Re: script to copy file from several directories

>Steven: but if one doesn't wish to leave a hole at midnight, then shouldn't those be either:

Right:
# touch -t 201101312359 file1
# touch -t 201102282359 file2

True if the current file has been modified more recently than the argument file.
F > file1 and F <= file2
Steven Schweda
Honored Contributor

Re: script to copy file from several directories

> Right:

"-newer" is another of those things where VMS
appears to have been thoughtfully designed,
while UNIX appears to have been thrown
together by someone in his spare time.
Having to figure out the last valid time
value before the time you really care about
would be even more annoying on VMS, where
file date-time values are maintained to
0.01s. For example:

Created: 17-FEB-2011 06:15:21.58
Revised: 17-FEB-2011 06:15:21.65 (1)
Expires:
Backup: 2-APR-2011 00:58:15.36

All those ".99" things would certainly annoy
me, if I had to use them. (But I don't.)