Solved

environment variables

Posted on 2002-03-25
14
436 Views
Last Modified: 2013-12-27
I have a script in rc2.d (S80ostore4) this sets some environment variables and then runs the Ostore license manager.  On my old system, I can type  echo $OS_ROOTDIR and I get  /opt/ODI/OS5.0/sunpro.
When I type this on my new system, The $OS_ROOTDIR returns a blank line.

It is the same script in /etc/rc2.d on both machines.  What are some reason for the new machine to not keep exported variables???

Can I get some help in making these exported variables maintain their value throughout all the new session.

0
Comment
Question by:carydb
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 4

Expert Comment

by:newmang
ID: 6895360
Can you post the contents of the script please. Also, what release of Solaris are you running?

Cheers - Gavin
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6895997
Start the script with

. ./script

and the environment variables is OK !!!

First point is for environment variables
in your shell.



0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6896027
point, blanc, point,slash,script
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:carydb
ID: 6896586
okay, Here is the script.  It is in /etc/rc2.d so it runs automatically when system is booted.  After it runs, the $OS_ROOTDIR var is no longer set.  Apparently it reamins set only through the execution of the script.

#!/sbin/sh
# Generated automatically by osconfig on Wed Oct 28 12:12:55 EST 1998
# [ ObjectStore Release 5.0 ]
USAGE="Usage:  $0 <start | stop>";
if [ $# -ne 1 ]; then
   echo $USAGE;
   exit 1;
fi
OS_ROOTDIR=/opt/ODI/OS5.0/sunpro ;
export OS_ROOTDIR ;
PATH=/opt/ODI/OS5.0/sunpro/bin:/sbin:/usr/sbin:/usr/bin:$PATH ;
export PATH ;
echo $PATH
LD_LIBRARY_PATH=$OS_ROOTDIR/lib:$LD_LIBRARY_PATH ;
export LD_LIBRARY_PATH ;
SHLIB_PATH=$OS_ROOTDIR/lib:$SHLIB_PATH ;
export SHLIB_PATH ;
action=$1;
UNAME=`uname -n`;
case $action in
  start_msg)
        echo "Starting ObjectStore server"
        ;;
  stop_msg)
        echo "Shutting down ObjectStore server"
        ;;
  start)
        if [ ! -d /tmp/ostore ] ; then
          mkdir /tmp/ostore;
          chmod 775 /tmp/ostore;
        fi
        if [ -f /opt/ODI/OS5.0/sunpro/etc/${UNAME}_server_parameters ] ; then
 
            if ossvrping ${UNAME} > /dev/null 2>&1 ; then
                :
            else
                /opt/ODI/OS5.0/sunpro/lib/osserver;
                res=$?;
                if [ $res -ne 0 ] ; then
                    echo ObjectStore server startup failed 1>&2;
                    exit 1;
                fi
           fi
        fi
        ;;
  stop)
        if /opt/ODI/OS5.0/sunpro/bin/ossvrping ${UNAME} > /dev/null 2>&1 ; then
            /opt/ODI/OS5.0/sunpro/bin/ossvrshtd -f ${UNAME};
        fi
        /opt/ODI/OS5.0/sunpro/bin/oscmshtd ${UNAME} > /dev/null 2>&1 ;
        ;;
  *)
        echo $USAGE;
        exit 1;
        ;;
esac
exit 0;
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6898575
Is normal , if a process work
is in your shell.

Example:
This script:
export TEST
echo 'HALLO'

If you start with:
./script
HALLO
end if you make
echo $TEST

is nothing.

If you start with:
. ./script
HALLO
end if you make
echo $TEST
/usr




0
 

Author Comment

by:carydb
ID: 6902678
This script is in the /etc/rc2.d directory and is envoked at system boot up.  I do not envoke it on the command line. I don't have the option of envoking it myself. The system runs it at boot up.  It works fine on a different machine.

I tried to envoke it as you suggested but the screen disappeared.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6904686
depending on your shell, you need to write the environment variabl settings in the appropriate rc-files, like:
   ~/.profile   or   ~/.cshrc   or   ~/.login

(don't forget to export)
0
 

Author Comment

by:carydb
ID: 6905621
Let me revise the problem.  The reason that the variables do not remain set is that for some reason when any script on my system is sourced

. ./scriptname

If there is an exit(0) command in it, It just blows away the window in which the script was attempting to run.

there is something wrong with my system for it to not run scripts that have exit(0) in it.  

Is this a known problem in Solaris 8? Any ideas?
0
 
LVL 5

Expert Comment

by:ecw
ID: 6905766
no, if you source a script, it runs in the context of the current shell, thus any exit in sourced script is an exit from the current shell.  rc scripts are not designed to be sourced, if you need the env vars, put the defs elsewhere and source that.
0
 

Author Comment

by:carydb
ID: 6905795
ecw, Ohh!  I see.   But I do have the rc2.d script that exports env variables just fine for a machine running 2.6
My new machine running 2.8 does not maintain these variables after the rc2.d script (S80ostore4) completes running.
How can this be.  
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6906630
please post results of following:

\uname -a; \echo $SHLVL; \echo $SHELL; \which $SHELL; \which exit
0
 
LVL 5

Accepted Solution

by:
ecw earned 75 total points
ID: 6907479
Even in 2.6, a rc script will not export env vars unless it is sourced and doesn't explicitly exit.  Login shells are not in any way related to rc scripts (apart from dtlogins).  If the env vars are correct when you login to 2.6, something other than the rc script must be setting them, probably something either in or called by one of your .profile, .dtprofile or /etc/profile.  Examine these and you'll probably find the answer.
0
 
LVL 1

Expert Comment

by:alextr
ID: 6910480
As ecw posts, probably there is a different settimg of the variable in your previous environment. By the way, in you 2.6 env, what is the login that has the variable set?
0
 

Author Comment

by:carydb
ID: 6916273
Sheesh!  Just when I thought I had it figured out.....

The /etc/profile was in fact setting the env variables.  I was thown off because the rc2.d script to which I referred actually exported those vars. I guess that was to initially run the ostore program and then users had their env set with the /etc/profile.

Live and learn.  Thanks.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question