0

I can tell you this is the craziest thing I have seen in a long time.

I have this (part of) sh script running on CentOS 5.4:

# Check GOLD_DIR`
echo $GOLD_DIR"<--"
#export GOLD_DIR=/share/apps/GOLD_Suite/GOLD <uncommenting this line works!!
if [ "X$GOLD_DIR" =  "X" ] ; then
  echo "ERROR: GOLD_DIR is (probably) not set on host ${HostName}" >> ${3}
  exit 1
fi

And this gives the following output:

/share/apps/GOLD_Suite/GOLD<-- 
Waiting for 5 seconds ..... Testing output

The test script did spawn a job (i.e. PVM ran OK), 
but errors were detected in the test script output 
on the host machine: Below is the output

ERROR: GOLD_DIR is (probably) not set on host xxx.yyy.local

As you can see the GOLD_DIR variable is set (the script finds it as shown by the output with postfixed "<--") ! If I uncomment the export of the GOLD_DIR variable in the script code (first snippet) everything works.

EDIT: GOLD_DIR is exported in /etc/profile (using export GOLD_DIR=/share/apps/GOLD_Suite/GOLD)

Any ideas why?

Note1: I don't know if this is important but this is a spawn script on PVM.

Note2: The script is written in sh #!/bin/sh but I am using bash...

Edit3: I GOT IT TO WORK BUT I DONT KNOW WHY! - Ok so what I did was rename the hostname (with sudo hostname abc) to the name of the machine I ssh into (e.g. abc). Before the PVM was listing the full name of the machine abc.mycompany.local. Note that both abc.mycompany.local and abc are the same machine.

MalteseUnderdog
  • 1,971
  • 5
  • 17
  • 17

2 Answers2

0

So the var is set. If you just do export GOLD_DIR instead of commented line (without setting the value), will it work?

Also. It's an isolated case? Is it bash there on CentOS? Try to use [[ ]] to check what's working wrong.

  • No it does not work. I can see the variable contents if I do an echo right after your statement but I still get the ERROR: ... bit. – MalteseUnderdog Feb 08 '11 at 11:06
  • I am using bash - but the script shbang is #!/bin/sh. I've changed to [[ ]] instead of [] and I still get the darn error – MalteseUnderdog Feb 08 '11 at 11:16
  • @MalteseUnderdog: So it's something with a variable value probably... Can you try `declare -p` on it? Maybe there's something suspicious about it. If you split the working export GOLD_DIR=blabla to assignment and then export, will it change something? Also try with POSIX mode like in POSIXLY_CORRECT envvar. If you change the condition to `[ -z "$GOLD_DIR" ]`, will it work? –  Feb 08 '11 at 11:24
0

I believe that it might have something to do with the non-interactive nature of the job. Jobs run from shell scripts won't necessarily source /etc/profile, so they might not be picking up your ${GOLD_DIR} variable. (Unless you've explicitly changed its behavior, bash will only source /etc/profile for a login shell.)

Try adding:

. /etc/profile

in the beginning of your script just to see if that changes anything. If not, when you echo the error statement, add in ${GOLD_DIR} somewhere to see if the variable is still available in that statement.

davidr
  • 35
  • 5