HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

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

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

Re: find command in crontab

>JRF: Whenever you use shell wildcards (metacharacters) with a 'find' command, you should quote the argument to avoid interpretation by the shell.

That's only if they are in -name or -path. Where they were was fine and needed to be expanded.
(That's why I asked "Doesn't work how?".)