1846606 Members
1808 Online
110256 Solutions
New Discussion

Re: Script

 
SOLVED
Go to solution
Indira Aramandla
Honored Contributor

Script

I need to remote copy files that are older than 2 hours. Can some one provide me the script. I tried using the -newer oftion with the find but could not succeed.

On server S1 in direcotry D1 the files get generated every 10 minutes. I need to remotely copy all the files older than 2 hours to the server S2 into a directory D2.


Thanks in advance.
Never give up, Keep Trying
13 REPLIES 13
Steven E. Protter
Exalted Contributor

Re: Script

A start:

find ${TmpDirList} -type f -mtime +${OLDEST}

This snippet goes after files more than a certain number of days old.

If you -mtime to -ctime 2 that will allow you to gather a list of files more than two hours old for processing.

find ${TmpDirList} -type f -ctime 2

The TmpDirList parameter is a list of directory to scan.

use the -print command to make a list for further processing.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Indira Aramandla
Honored Contributor

Re: Script

Hi Steven,

Thanks a lot for the quick reply.

I tried as you suggested.

Here is the directory listing.

-rw-rw---- 1 oracle dba 8550969 Dec 4 06:39 arch4473_rprd.log.Z
-rw-rw---- 1 oracle dba 8592471 Dec 4 06:41 arch4474_rprd.log.Z
-rw-rw---- 1 oracle dba 8501743 Dec 4 06:51 arch4475_rprd.log.Z
-rw-rw---- 1 oracle dba 8837264 Dec 4 06:53 arch4476_rprd.log.Z
-rw-rw---- 1 oracle dba 5980036 Dec 4 07:00 arch4477_rprd.log.Z
-rw-rw---- 1 oracle dba 2074509 Dec 4 08:00 arch4478_rprd.log.Z
-rw-rw---- 1 oracle dba 8019762 Dec 4 09:00 arch4479_rprd.log.Z
-rw-rw---- 1 oracle dba 8892805 Dec 4 09:20 arch4480_rprd.log.Z
-rw-rw---- 1 oracle dba 9192857 Dec 4 09:46 arch4481_rprd.log.Z
-rw-rw---- 1 oracle dba 9218013 Dec 4 10:10 arch4482_rprd.log.Z
-rw-rw---- 1 oracle dba 9350541 Dec 4 10:40 arch4483_rprd.log.Z
-rw-rw---- 1 oracle dba 6750444 Dec 4 11:00 arch4484_rprd.log.Z
-rw-rw---- 1 oracle dba 9333897 Dec 4 11:33 arch4485_rprd.log.Z
-rw-rw---- 1 oracle dba 9514487 Dec 4 12:07 arch4486_rprd.log.Z

I tried this⠦⠦⠦⠦⠦⠦

find -type f â ctime 2 â print and I did
Never give up, Keep Trying
Elmar P. Kolkman
Honored Contributor

Re: Script

The problem with mtime and ctime is that they are in days, not hours...

What you need to to use find is by creating a temporary file with the correct mtime by using touch and then do the find with ! -newer

It will look like this:
touch -t 200312040800 /tmp/tmpf
find . ! -newer /tmp/tmpf -print
rm /tmp/tmpf

Biggest issue this will give is of course the creation of the tempfile, since you need to calculate the correct time value. Now this can be done easily with perl:

#!/usr/local/bin/perl
use POSIX qw(strftime);
print strftime("%Y%m%d%H%M",time()-120);
Every problem has at least one solution. Only some solutions are harder to find.
Indira Aramandla
Honored Contributor

Re: Script

Hi Elmar,

Thanks for the suggestion. Yes I ca list the file older that the time the temp file was created by tough -t ccyymmddhhmi.

Now I tried to copy these files as
find -name '' -newer temp_file -depth | cp -p .

I cannot copy like this, as cp will require the source file name.

Any suggestions, to cpoy the listed file along with the find command.

Thanks
Never give up, Keep Trying
Jean-Louis Phelix
Honored Contributor
Solution

Re: Script

Hi,

Elmar solution is of course correct. For time calculation on hours, I've once found a clever tip on the forum :

/homeHA/phelix> echo $TZ
MET-1METDST
/homeHA/phelix> date +'%Y%m%d%H%M'
200312040810 # --> 8 in the morning
/homeHA/phelix> TZ=MET+1METDST date +'%Y%m%d%H%M' # add 2 hours to MET-1
200312040610 # 2 hours earlier !!!

So depending on your TZ value, just use :

touch -t $(TZ=MET+1METDST date +'%Y%m%d%H%M') /tmp/foo
find xxx ! -newer /tmp/foo -exec cp -p {} destination \;

Regards.
It works for me (© Bill McNAMARA ...)
Michael Schulte zur Sur
Honored Contributor

Re: Script

Hi,

use:
find -name '' -newer temp_file -depth -exec cp -p '{}' ';'

greetings,

Michael

Indira Aramandla
Honored Contributor

Re: Script

Hi All,

Thanks for your good replies. Jean the script works now. Thanks to all you replied.



Indira
Never give up, Keep Trying
Michael Schulte zur Sur
Honored Contributor

Re: Script

Hi Indira,

I wonder whether Jeans solution with the TZ is supported? ;-) It has another drawback. You can use only that for full hour differences, right? Once I was looking for a solution for a problem just like this. Find is only able to count in days, so I wrote a small c programme which is in the attachment. This will allow you to specify seconds.

Use:
# cat t10
#!/bin/ksh
find /tmp -name '*' -depth -exec ./t101 '{}' ';'

# cat t101
#!/bin/ksh
./fage ${1} 3600 || echo cp -p ${1} "destination"
Michael Schulte zur Sur
Honored Contributor

Re: Script

Hi Indira,

compile c programme with:
cc -o fage fage.c

it should be 7200 instead of 3600.

greetings,

Michael
Mike Stroyan
Honored Contributor

Re: Script

Michael Schulte asked if timezone tricks are limited to full hour increments. You can actually set a timezone to single second increments! It is documented in "man environ".

There are three different timezones in the /sbin/set_parms.d/10_timezone list which have 30 minute offsets from their neighbors.

Zname[1]=NST3:30NDT
Zfull[1]="Newfoundland Standard/Daylight"

Zname[3]=SAT4:30
Zfull[3]="Venezuela, Guyana, Surinam"

Zname[2]=IST-5:30
Zfull[2]="India"
Jeromy Gregg
Advisor

Re: Script

I like the suggestion about using find, and the suggestion about manipulating the TZ was very creative, but one thing which would quickly and efficiently do what you are describing is the rdist utility, available at http://hpux.cs.utah.edu/hppd/hpux/Networking/Admin/rdist-6.1.5/, or http://www.magnicomp.com/rdist/.

When using RDIST, you can specify a directory. Rdist then evaluates which, if any of the files in the source (local) directory are not present on the target (remote) directory and then copies them over. RDIST is very simple to configure. You can put the commands in control file, called a dist file, and then run rdist with the -f distfile switch in cron to get consistent results every time.

Good Luck!
Michael Schulte zur Sur
Honored Contributor

Re: Script

Hi Mike,

yes, you are right. I know now!!

be happey,

Michael
Indira Aramandla
Honored Contributor

Re: Script

Closing this thread. The -newer parameter in find did the job.


Indira A
Never give up, Keep Trying