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

Re: cron and command quote



Bob McGowan wrote:
Jeff D wrote:

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


Both are legal, but && is really what he is looking for:

jeffd@ontz:/tmp$ nocommand || echo "ok"
bash: nocommand: command not found
ok
jeffd@ontz:/tmp$ date|| echo "ok"
Tue Mar 18 11:35:54 PDT 2008
jeffd@ontz:/tmp$ date && echo "ok"
Tue Mar 18 11:35:59 PDT 2008
ok
jeffd@ontz:/tmp$ nocommand && echo "ok"
bash: nocommand: command not found

so with || we get execute command1 OR command2, whic ever one executes first. I don't believe that this would be the desired result in this situation.

with && we have execute command1 if it returns true execute command2




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


Reply to: