Operating System - HP-UX
1752812 Members
5837 Online
108789 Solutions
New Discussion

cron - LANG variable being set causes child process to be spawned

 
D Heindel
Occasional Advisor

cron - LANG variable being set causes child process to be spawned

We were burned by some unexpected behaviour by the cron subsytem.  We have a command that is being executed by the cron daemon using the at command.  It appears that if the LANG variable is set, when the at command builds the script file that will be executed, at the top of the file it will add a line to export the LANG variable and then start a new shell process.  For example:

 

my_script.sh:

 

export my_env="some value"

echo "my_env = $my_env"

if [ "true" = "true" ]; then 

  echo "Error - exiting"

  exit 1

fi

echo "still running - now my_env = $my_env"

 

When the at command processes this file (at -f my_script.sh now) and builds the script that is put in the /var/spool/cron/atjobs directory it adds the following lines to the top:

 

export LANG; LANG=en_US.iso88591

/usr/bin/sh

....

 

The result is that because it is initiating this child shell process, when the condition evaluates to false it only exits out of the child process and continues on with the rest of the script (and any environment variables set while in the child process are now unset).  So the output from the above script would look something like:

 

my_env = some value

Error -exiting

still running - now my _env = 

 

I am assuming it is doing this because the LANG variable needs to be set before the shell is initiated to have an affect.  The only way have found to prevent this is to unset the LANG variable before calling the at command.  Is there a better way to control this? Does this behaviour indicate a configuration setup issue on the server?  One thing I have noticed is that the LANG variable is when connecting to the server via remsh and not when signing in through telnet.

1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: at - LANG variable being set causes shell child process to be spawned

(This has nothing to do with cron, it's all done by at(1).)

 

>When the at command processes this file (at -f my_script.sh now) and builds the script that is put in the /var/spool/cron/atjobs directory it adds the following lines to the top:

export LANG; LANG=en_US.iso88591

/usr/bin/sh

 

There is nothing wrong with the export of LANG.  The shell doesn't belong there.

at(1) takes a file of commands, not a script!

So you may have to use:

at ... <<EOF

my_script.sh

EOF

 

Looking closely at what you said, it appears you don't have that shell line in your my_script.sh?

If so, there may be something wrong with your /var/adm/cron/.proto?

What OS version are you using?  There may be a patch for this?