Solved

environment variables

Posted on 2002-03-25
14
434 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
Comment Utility
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
Comment Utility
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
Comment Utility
point, blanc, point,slash,script
0
 

Author Comment

by:carydb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:carydb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now