Operating System - HP-UX
1748243 Members
4314 Online
108760 Solutions
New Discussion юеВ

Re: find command in crontab

 
SOLVED
Go to solution
Ratzie
Super Advisor

find command in crontab

I need to run a find command inside the crontab.
For some reason this does not work...

00 11 * * * find /home/oracle/scripts/logs/*acdb_online_backup_level* -mtime -14 -exec rm -rf {} + 2>/dev/null
10 REPLIES 10
Dennis Handly
Acclaimed Contributor

Re: find command in crontab

Doesn't work how? find(1) should be in your limited cron path.

I don't see any special "%" chars.
What HP-UX version are you using?
James R. Ferguson
Acclaimed Contributor
Solution

Re: find command in crontab

Hi:

Whenever you use shell wildcards (metacharacters) with a 'find' command, you should quote the argument to avoid interpretation by the shell. Too, your 'cron' environment is very likely to differ from your normal login one. Try:

# 00 11 * * * find "/home/oracle/scripts /logs/*acdb_online_backup_level*" -mtime -14 -exec rm -rf {} + 2>/dev/null

That said, I really think you want to do:

# 00 11 * * * find /home/oracle/scripts/logs -name "*acdb_online_backup_level*" -mtime -14 -exec rm -rf {} + 2>/dev/null

Regards!

...JRF...
Ratzie
Super Advisor

Re: find command in crontab

Nope still does not not.
I see it run in the cron log. So cron does run, but have tried multiple ways.



05 10 * * * find /home/oracle/scripts/logs -name "*acdb_online_backup_level*" -mtime -1 -exec rm -rf {} + 2>/dev/null

05 10 * * * find /home/oracle/scripts/logs -name "*acdb_archivelog_backup*" -mtime -1 -exec rm -rf {} + 2>/dev/null

15 10 * * * find "/home/oracle/scripts/logs/*acdb_archivelog_backup*" -mtime -1 -exec rm -rf {} + 2>/dev/null
Patrick Wallek
Honored Contributor

Re: find command in crontab

Does this work from the command line?

I would modify the script so that it e-mails you error rather than just sending them to /dev/null.

find "/home/oracle/scripts/logs/*acdb_archivelog_backup*" -mtime -1 -exec rm -rf {} + 2>&1 | mailx -s "find output" you@someaddress.com
Michael Steele_2
Honored Contributor

Re: find command in crontab

Shouldn't...
-rf {} + 2>&1 |
be...
-rf {} \;
Support Fatherhood - Stop Family Law
James R. Ferguson
Acclaimed Contributor

Re: find command in crontab

Hi (again):

> Michael: Shouldn't... -rf {} + 2>&1 | be...
-rf {} \;

No. Using the '+' terminator with '-exec' greatly improves performance. Multiple arguments are collected and passed to each process spawned. This acts much like a pipeline to 'xargs' would and has been available since 11.0.

Regards!

...JRF...
Ratzie
Super Advisor

Re: find command in crontab

I can run:
find /home/oracle/scripts/logs/*acdb_online_backup_level*.log

But once I add the -mtime -1 or any number, I get nothing.

Exactly the same thing if I run it like:
find /home/oracle/scripts/logs -name "*acdb_online_backup_level*.log"
-get results

find /home/oracle/scripts/logs -name "*acdb_online_backup_level*.log" -mtime -5
-No results
Ratzie
Super Advisor

Re: find command in crontab

I am the dummy here...
mtime +5! Not -5

Arggg!
Michael Steele_2
Honored Contributor

Re: find command in crontab

Thank you James.
Support Fatherhood - Stop Family Law