help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Cron jobs and env vars


From: Greg Wooledge
Subject: Re: [Help-bash] Cron jobs and env vars
Date: Fri, 30 Nov 2012 08:09:39 -0500
User-agent: Mutt/1.4.2.3i

On Thu, Nov 29, 2012 at 08:05:13PM -0800, Mun wrote:
> I need to run a cron job that launches a script to set up environment
> variables which are needed for a successive script call.  I have
> included a representation of my script below.  I am experiencing
> behavior which I cannot explain with the environment variables.

I don't understand what "successive script call" means.  Do you mean
that you are launching a second script as a child of the first one?
Or are you exec-ing a second script to replace the first one?  Or
do you mean "commands that appear later on in the first script"?

> #! /bin/bash
> 
> export SHELL="/bin/bash -i"
> 
> /path/setUpEnvVars arg1 arg2 &> /home/mun/out.log <<EOF_REGR
> 
> printenv             // Correctly dumps env vars set up via setUpEnvVars
> echo $VAR1           // VAR1 (set in setupEnvVars) appears unset
> printenv|grep VAR1   // VAR1 is correctly printed
> echo $HOME           // HOME is correctly printed
> 
> exit
> EOF_REGR

Your here document delimiter is not quoted.  This means that bash, while
processing this script, performs replacements of $VAR1 and $HOME inside
the body of the here document.  If you quote the delimiter, like this:

/path/setUpEnvVars >log 2>&1 <<'EOF_REGR'
echo "$VAR1"
etc.
EOF_REGR

then it will pass $VAR1 through to setUpEnvVars without expanding it.

That said, you appear to be feeding (almost) bash commands to something
called /path/setUpEnvVars.  I have no idea what this thing is.  It had
better be able to read bash commands as input, but with C++ style
comments, because that's what you seem to be giving it.

Also, if you intended that "setUpEnvVars" would populate the environment
of bash so that you could use those variables AFTER setUpEnvVars has
exited, you will be disappointed.  Since setUpEnvVars is a child process,
any changes it makes to the environment are lost when it exits.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]