cron fails; command line OK

cron fails; command line OK

Post by Greg Ruffin » Thu, 07 Jan 1999 04:00:00



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.
 
 
 

cron fails; command line OK

Post by Neil Nú?e » Thu, 07 Jan 1999 04:00:00


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.


 
 
 

cron fails; command line OK

Post by Ram Pandi » Thu, 07 Jan 1999 04:00:00


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.

 
 
 

cron fails; command line OK

Post by Greg Ruffin » Fri, 08 Jan 1999 04:00:00


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?
 
 
 

cron fails; command line OK

Post by Matt Willma » Fri, 08 Jan 1999 04:00:00


I've seen similar things happen when cron interprets special characters
before passing them on to the shell.  Have you tried escaping the * in
the
middle of your command line?

Matt


> 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 {} \;

SNIP
 
 
 

cron fails; command line OK

Post by Alan Hamilt » Wed, 13 Jan 1999 04:00:00


On Thu, 07 Jan 1999 09:04:19 -0500, Greg Ruffing


>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.

 
 
 

cron fails; command line OK

Post by Mike » Wed, 13 Jan 1999 04:00:00


This also worked for me...

55 2 * * * find /apps/d2/outputs -name "*" -type f -mtime +7 -exec rm {}
"\";

quoting the last \   i.e. "\"

mike


>On Thu, 07 Jan 1999 09:04:19 -0500, Greg Ruffing

>>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.

 
 
 

cron fails; command line OK

Post by David Marti » Fri, 19 Mar 1999 04:00:00


I always specify full pathnames for commands in cron.
eg./usr/bin/find, /usr/bin/rm
I don't think this is your problem though since /usr/bin is usually in
the path.



> > 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

--

Bureau of Meteorology, Melbourne, Australia,
Planet Earth, Sol Solar System, Milky Way, Only Known Universe
 
 
 

cron fails; command line OK

Post by Norman Levi » Fri, 19 Mar 1999 04:00:00


In AIX V4, sh is ksh.  I think the \; is eaten by cron so all that is left to
execute is -exec rm {} ;
and the shell sees a continuation and you don't have one.
Try \\; or put the whole thing in quotes.
--
Norman Levin
vm/dynAmIX inc.
 
 
 

cron fails; command line OK

Post by Frank Van Overloo » Fri, 19 Mar 1999 04:00:00


Yes,

I can confirm this. I had the same problem and solved it by puttin \\\; at
the end of the statement.


>In AIX V4, sh is ksh.  I think the \; is eaten by cron so all that is left
to
>execute is -exec rm {} ;
>and the shell sees a continuation and you don't have one.
>Try \\; or put the whole thing in quotes.
>--
>Norman Levin
>vm/dynAmIX inc.

 
 
 

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

10. Command Line and Cron

11. How to tell if script is run from cron or command line?

12. Command Line Script runs fine get bad substititon from cron