[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cron and command quote



Jeff D wrote:
T o n g wrote:
On Tue, 18 Mar 2008 03:40:35 +0100, s. keeling wrote:

I.e., somehow, the 'ps | grep' was able to find something in cron, whereas
 when executed directly under shell:

$ ps -eaf | grep -E 'cdrecord.* -[dts]ao |cdrdao *write|growisofs.*speed='

$ /bin/sh -c "ps -eaf | grep -E 'cdrecord.* -[dts]ao |cdrdao *write|growisofs.*speed='"

I.e., if the same command are executed directly under shell the 'ps | grep' finds nothing.
 Anyone can give some explanation?
Yes.  you're stressing either the tool, or your knowledge of it.  Put
the relevant bits in a shell script and tell cron to execute that.
Then you'll have full control.  It won't be hampered by cron's (by
design) limitations.

Nope, that didn't work. Thanks for the suggestion though s. keeling.
Here is what happened after I followed the above advice.

Now the crontab reads:

 * * * * *    root    is_burning || logger get executed.

+ set -x
+ ps -eaf
+ grep -E  -[dts]ao |cdrdao *write|growisofs.*speed='
root 15306 15295 0 09:29 ? 00:00:00 grep -E cdrecord.* -[dts]ao |cdrdao *write|growisofs.*speed=
+ exit 0

$ is_burning || echo not burning CD/DVD
not burning CD/DVD

I.e., having put the 'ps | grep' part into a shell script, the behavior is
still the same.
Does it has anything to do with busybox?

Thanks


|| will not return true for you here, ever. you need to use && or use an if statement. Also, if you are going to be using a shell script you have to make sure that it exits properly. I would recommend putting the whole thing into a shell script:

if ps -eaf | grep -v grep | grep -E 'cdrecord.* -[dts]ao |cdrdao \ *write|growisofs.*speed=' >> /dev/null 2>&1 ; then
    logger get executed
fi



Jeff,

I'm confused, here. You say that using '||' will never work because it will not return true. I presume you mean the '||' used in the cron file? But, according to the the crontab man page, anything after the fifth time column, up to the end of the line, is run by a shell, either /bin/sh or whatever is in the SHELL variable of the crontab file.

So, '||' is just as legal as '&&' and would do just as it does on the command line, assuming of course there is nothing found by the grep.

I don't think the problem is the use of the OR or AND operators. Rather it's the presences or absence of the line for the grep itself being found in the ps output.

But I may be missing something obvious?

--
Bob McGowan

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Reply to: