cancel
Showing results for 
Search instead for 
Did you mean: 

crontab commands fail

 
Kanwar
Occasional Advisor

crontab commands fail

Hi,
I am a DBA with HP in Sydney. We have a peculiar issue with crontab entries that we are unable to resolve.

A typical crontab entry looks like
NN NN * * * find -name '*trc' -exec chmod o+r {} \; >/dev/null 2>&1

Now, if there are files in , its ok. But if there are no files in , the above command throws a ticket with an alert that the command failed.
I have tried modifying the command in various ways--one such attempt is listed below--but that fails as well.

NN NN * * * [ $(ls -1A | wc -l) != 0 ] && find .....

So, I try to count if there are files in before I run the find and yet I get the error that "ls -1A etc" has failed.

Is there a way to insulate commands in cron so that if there are no files to operate on, the command should just go away? Basically, if there are no files in , it is not an error --from Oracle point-of-view.

Please advise.

Thanks,
Kanwar
6 REPLIES
George Spencer_4
Frequent Advisor

Re: crontab commands fail

Hi Kanwar,

What happens if you use a + at the end of the find command. The escaped \; is not going to work from crontabs.

Regards,

George
Kanwar
Occasional Advisor

Re: crontab commands fail

Hi George,

Thanks for the quick reply. Can you give me an example of how I can add the '+' at the end?

Is it:

NN NN * * * find -name '*.trc' -exec chmod o+r {} + ??
Kanwar
Occasional Advisor

Re: crontab commands fail

To avoid the \; at the end of find command, I have now modified it to find ... | xargs.

Is this a better approach?
Suraj K Sankari
Honored Contributor

Re: crontab commands fail

Hi Kanwar,

If possible write a shell program and execute from crontab.

Suraj
Kanwar
Occasional Advisor

Re: crontab commands fail

Thanks Suraj, I will try that.

Thanks all.

Re: crontab commands fail

It appears find(1) is broken because it doesn't document its exit status.

>Is there a way to insulate commands in cron so that if there are no files to operate on, the command should just go away?

You can just ignore all errors from the find:
NN NN * * * find -name '*trc' -exec chmod o+r {} + > /dev/null 2>&1; true

>I have now modified it to find ... | xargs.
>Is this a better approach?

No, using a "+" is much better.

>George: What happens if you use a + at the end of the find command. The escaped \; is not going to work from crontabs.

Using "+" will make it faster. But the "\;" should also work.

>Suraj: write a shell program and execute from crontab.

Yes, a shell script will allow you to set the exit status and check for no matches.