RE: crontab and exec

RE: crontab and exec

 

  

Joel,

You have to export all variables, otherwise they will not be available
after the exec.

Exec creates a new sub shell, and if you haven't exported everything
(variables, including $PATH)
you wind up with no environment at all, again, just like running from
cron to begin with:

<paste>

> ECHO=/bin/echo
> MWB>>> export ECHO

MWB>>>exec 1>/tmp/file.lis2 2>&1

> $ECHO "Here I don't go " >> /u01/file.lis
>

A test like:
exec ls -al /tmp
will probably work, your .profile/.bashrc/.etc probably exports PATH.

So even if you have:
#!/bin/ksh
. /home/oracle/.profile
exec <blah>

AND the .profile doesn't export variables, you won't have
everything available from the .profile (things that are not exported).

In house, we created a cron.profile, stick it somewhere common
(e.g. /usr/local/bin/)
And build it up with variables and exports:
LS=/bin/ls
export LS
WHO=/bin/who
export WHO,
etc...
[We use sh syntax so this can be used at boot]
And now all cron jobs can just source that, and have a decent "OS"
environment.

HTH,
Matt


On Fri, 2005-12-30 at 07:45 +0800, Williams Trevor wrote:

> Joel
>
> If you haven't done so already, you might confirm that replacing
> ${file} with an actual file name displays the same symptom. Maybe even
> remove the single quote from the final echo.
>
> I ran
>
> #!/usr/bin/ksh
> #tmw
> echo "Here I go " >> /tmp/file.lis1
> exec 1>/tmp/file.lis2 2>&1
> echo "utilizing exec"
> echo "Here I don't go " >> /tmp/file.lis1
>
> from HP-UX cron and it worked according to Hoyle. 2 lines in .lis1 and
> the one in .lis2. Same result with #!/usr/bin/sh.
>
> Do you capture the cron output thusly?:
> 32 07 * * 5 /home/dba/bin/tmwtest >/tmp/tmwtest.cron 2>&1
>
> Unlikely, but ...
> Do you know that your online shell is the same as the one which cron
> uses?
> If your linux has a non-bash shell, maybe you could try that?
>
> Trevor
>
>


----------------------------------------------------------------
|Matthew W. Ball (Matt)
|Team Lead for Infrastructure and Reliability Group
|Endeavor Information Systems Inc.
|(e) [Email address protected]
|(p) 847-227-2678
|(f) 208-275-0869
|(u) http://www.endinfosys.com
--------------------------------------------------------------
#define THE_QUESTION
(( (bb) || ! (bb) ))
- W. Shakespeare
--------------------------------------------------------------

Oracle LazyDBA home page