Operating System - HP-UX
1832670 Members
3572 Online
110043 Solutions
New Discussion

cron to copy and keep it for 1 day

 
SOLVED
Go to solution
kholikt
Super Advisor

cron to copy and keep it for 1 day

I am doing some cron job to copy the oracle arch log file from saparch to saparchlocal just for archiving purpose. I need to purge the saparchlocal if the file is older than 1 day but it doesn't seem to purge for any file older than 1 day.

00,15,30,45 * * * * find /oracle/TRP/saparch -name '*arch*dbf' -newer /oracle/TRP/saparchlocal -print -exec cp -p {} /oracle/TRP/saparchlocal \;
00,15,30,45 * * * * find /oracle/TRP/saparch -name 'archTRP.log' -newer /oracle/TRP/saparchlocal/archTRP.log -print -exec cp -p {} /oracle/TRP/saparchlocal \;
0 3,12,20 * * * find /oracle/TRP/saparchlocal -name '*arch*dbf' -mtime +0 -print -exec rm {} \;
abc
7 REPLIES 7
Joseph Loo
Honored Contributor
Solution

Re: cron to copy and keep it for 1 day

hi,

if u try the following:

# find /oracle/TRP/saparchlocal -name '*arch*dbf' -mtime +0 -print -exec ls -ld {} \;
or
# find /oracle/TRP/saparchlocal -name '*arch*dbf' -atime +0 -exec ls -ld {} \;

r there any listing of the archive logs.

just for info, i have no problem using -atime to remove the archive log from my server.

regards.
what you do not see does not mean you should not believe
kholikt
Super Advisor

Re: cron to copy and keep it for 1 day

It give the following output

find /oracle/TRP/saparchlocal -name '*arch*dbf' -mtime +0 -print -exec ls -ld {} \;
/oracle/TRP/saparchlocal/TRParch1_2413.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 04:31 /oracle/TRP/saparchlocal/TRParch1_2413.dbf
/oracle/TRP/saparchlocal/TRParch1_2414.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:31 /oracle/TRP/saparchlocal/TRParch1_2414.dbf
/oracle/TRP/saparchlocal/TRParch1_2415.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:34 /oracle/TRP/saparchlocal/TRParch1_2415.dbf
/oracle/TRP/saparchlocal/TRParch1_2416.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:37 /oracle/TRP/saparchlocal/TRParch1_2416.dbf
/oracle/TRP/saparchlocal/TRParch1_2417.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 09:11 /oracle/TRP/saparchlocal/TRParch1_2417.dbf
/oracle/TRP/saparchlocal/TRParch1_2418.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 10:06 /oracle/TRP/saparchlocal/TRParch1_2418.dbf

find /oracle/TRP/saparchlocal -name '*arch*dbf' -atime +0 -exec ls -ld {} \;
-rw-rw---- 1 oratrp dba 41944064 Jun 22 04:31 /oracle/TRP/saparchlocal/TRParch1_2413.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:31 /oracle/TRP/saparchlocal/TRParch1_2414.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:34 /oracle/TRP/saparchlocal/TRParch1_2415.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 07:37 /oracle/TRP/saparchlocal/TRParch1_2416.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 09:11 /oracle/TRP/saparchlocal/TRParch1_2417.dbf
-rw-rw---- 1 oratrp dba 41944064 Jun 22 10:06 /oracle/TRP/saparchlocal/TRParch1_2418.dbf
abc
Joseph Loo
Honored Contributor

Re: cron to copy and keep it for 1 day

hi,

could u just perform the purging by replace "ls -ld" with rm without using cron for now, i.e.:

# find /oracle/TRP/saparchlocal -name '*arch*dbf' -atime +0 -exec rm {} \;

regards.
what you do not see does not mean you should not believe
T G Manikandan
Honored Contributor

Re: cron to copy and keep it for 1 day

Hi,

Why you are trying to copy the archive log files.

IF you need such a scneario then you can add a parameter in the Oracle database initialization file.
LOG_ARCHIVE_DUPLEX_DEST

Then you can remove those files from the specified directory using a script.

kholikt
Super Advisor

Re: cron to copy and keep it for 1 day

According to my dba they say that doesn't work
abc
Jeroen Peereboom
Honored Contributor

Re: cron to copy and keep it for 1 day

L.S.

Did you try Joseph's suggestion to remove the files with the same command from the commandline, so not using cron? Result?

Some other suggestions:
* Do you receive any emails from cron jobs failing?

* Whose cron job is it? Whose directory is it, what are the permissions on the directory?

* Can you try rm -f in stead of rm?


JP.
john korterman
Honored Contributor

Re: cron to copy and keep it for 1 day

Hi kholikt,

you could try first to make sure that there are files to delete, e.g. by this command:
# find /oracle/TRP/saparchlocal -name '*arch*dbf' -mtime +0 -print -exec ls -ltr {} \;

If no file appears then try this:
# set -x
and execute the command again in order to see how the wildcards expand: perhaps they do not match anything.

It would also be a good idea to redirect the output from the cron commands to specific files. If not, the output from the cron commands goes to the mail for the user in whose crontab the commands are executed - hence Jeroen's suggestion.

regards,
John K.
it would be nice if you always got a second chance