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

Re: cron and command quote



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


--
8 out of 10 Owners who Expressed a Preference said Their Cats Preferred Techno.


Reply to: