Try to put the command in a shell script
Quote:>I've got a puzzling problem...
>I have an entry in cron as follows:
>55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7
>-exec rm {} \;
>Mail is sent that says "incomplete statement" and the command
>does not execute.
>When I execute from the command line - it works.
>I think that it has not worked since we went from 3.2.5 to 4.3.2
>a couple of weeks ago, although I can't imagine that would
>matter.
>Thanks in advance for any ideas.
The backslash (\) needs to be escaped with another backslash
in the cron statement, as the shell gobbles it up trying to
execute.
Ram
|> I've got a puzzling problem...
|> I have an entry in cron as follows:
|> 55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7
|> -exec rm {} \;
|> Mail is sent that says "incomplete statement" and the command
|> does not execute.
|> When I execute from the command line - it works.
|> I think that it has not worked since we went from 3.2.5 to 4.3.2
|> a couple of weeks ago, although I can't imagine that would
|> matter.
|> Thanks in advance for any ideas.
--
______________________________________________
My views are mine, not IBMs.
Matt
find /apps/d2/outputs \( -name "*" -type f -mtime +7 \) -exec rm {} \;
becomes
find /apps/d2/outputs ( -name "*" -type f -mtime +7 ) -exec rm {} ;
sh chokes on the first (, which is supposed to be escaped so it gets
passed to find, not processed by sh. Anyway, the ()s are unnecessary
in this case. The trick, as your second example did, is to keep sh
from catching the ;, passing it to find instead. cron changes the \\;
to \; which is okay with sh.
55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7 -exec rm {}
"\";
quoting the last \ i.e. "\"
mike
>>Thanks for the suggestions for the following command that didn't
>>work in cron but did from command line:
>>55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7
>>-exec rm {} \;
>>I tried using a script and that worked.
>>I also tried the extra '\' as shown here:
>>55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7
>>-exec rm {} \\;
>>and that also worked.
>>The other suggestion:
>>55 2 * * * find /apps/d2/outputs \( -name "*" -type f -mtime +7
>>\) -exec rm {} \;
>>did not work. It returned an error:
>>sh: syntax error at line 1 : `(' unexpected
>>Can anyone explain?
>The problem is that cron is processing the special characters before
>passing them to sh for execution. So
>find /apps/d2/outputs \( -name "*" -type f -mtime +7 \) -exec rm {} \;
>becomes
>find /apps/d2/outputs ( -name "*" -type f -mtime +7 ) -exec rm {} ;
>sh chokes on the first (, which is supposed to be escaped so it gets
>passed to find, not processed by sh. Anyway, the ()s are unnecessary
>in this case. The trick, as your second example did, is to keep sh
>from catching the ;, passing it to find instead. cron changes the \\;
>to \; which is okay with sh.
> > Try to put the command in a shell script
> > >I've got a puzzling problem...
> > >I have an entry in cron as follows:
> > >55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7
> > >-exec rm {} \;
> > >Mail is sent that says "incomplete statement" and the command
> > >does not execute.
> > >When I execute from the command line - it works.
> > >I think that it has not worked since we went from 3.2.5 to 4.3.2
> > >a couple of weeks ago, although I can't imagine that would
> > >matter.
> > >Thanks in advance for any ideas.
> I like the idead of putting it in a shell script. But remember that cron uses
> sh as shell not csh or ksh.
> Either use the shell script and be sure to start with #!/bin/ksh or use
> /bin/ksh on the line in cron.
> David
I can confirm this. I had the same problem and solved it by puttin \\\; at
the end of the statement.
1. Script Runs Ok At Command Line, Not Cron
Hi. We're running AT&T Interactive Unix version 4.1.
We have a script that runs fine under root at the command prompt #.
However, when we include this script in our cron (root file) such as
30 15 * * * /path/to/script this is the error that shows up in the
mail:
Cannot read message file: operating system error 2
What is so different about running it on the command line vs a cron?
What am I obviously missing here? Thanks.
2. Things that make me go Hmm 2
3. Crontab fails but is ok on command line
4. Linux (RH6.1) + Arowana ISDN128 Terminal Adaptor
5. DIP/SLIP works great from command line, but fails as cron job (??)
6. ANNOUNCE: X-ISP: an X11 visual interface to pppd/chat
7. Can't login from X but command line is Ok
8. Bizarre 2.2 install message
9. Samba - W95 can't copy to share using explorer, command line ok
11. How to tell if script is run from cron or command line?
12. Command Line Script runs fine get bad substititon from cron