Solved

environment variables

Posted on 2002-03-25
14
438 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

860 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