LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unable to set env variables in a script (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-set-env-variables-in-a-script-4175463028/)

deep27ak 05-22-2013 11:51 AM

unable to set env variables in a script
 
Hello,

I am struggling with this script which I have to create to startup app database at reboot. Now the problem is before running the command to start the database I am suppose to set some environment variable for the system.

This is the file which contains all the env variable and manually I run using this command
Code:

# . tux.env
Code:

# less tux.env
TUXDIR=/u01/Tuxedo/tuxedo10gR3; export TUXDIR
JAVA_HOME=/u01/peoplesoft/jre; export JAVA_HOME
JVMLIBS=$JAVA_HOME/lib/amd64/server:$JAVA_HOME/jre/bin
PATH=$TUXDIR/bin:$JAVA_HOME/bin:$PATH; export PATH
COBCPY=:$TUXDIR/cobinclude; export COBCPY
COBOPT="-C ANS85 -C ALIGN=8 -C NOIBMCOMP -C TRUNC=ANSI -C OSEXT=cbl"; export COBOPT
SHLIB_PATH=$TUXDIR/lib:$JVMLIBS:$SHLIB_PATH; export SHLIB_PATH
LIBPATH=$TUXDIR/lib:$JVMLIBS:$LIBPATH; export LIBPATH
LD_LIBRARY_PATH=$TUXDIR/lib:$JVMLIBS:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
WEBJAVADIR=$TUXDIR/udataobj/webgui/java; export WEBJAVADIR

and after this the startup command
Code:

# psadmin -p start  -d fin91dmo
But If I want to automate my work adding this in a script as shown below
Code:

# less app.sh
#!/bin/bash

TUX_DIR="/u01/Tuxedo/tuxedo10gR3"
cd $TUX_DIR
. tux.env

PS_HOME=/u01/peoplesoft
sh $PS_HOME/psconfig.sh

psadmin -p start  -d fin91dmo
psadmin -c boot -d fin91dmo

Now every time I run this script it says
Code:

psadmin command not found
which means path variable are not getting set I believe.
Am I doing any thing wrong as I am not so good with scripts.
Is there any way I can automate this process?

Habitual 05-22-2013 12:29 PM

try
Code:

/path/to/psadmin -p start  -d fin91dmo
/path/to/psadmin -c boot -d fin91dmo

in the script.

pan64 05-22-2013 12:32 PM

or try set -xv at the beginning of the script (as second line)

rtmistler 05-22-2013 03:01 PM

Do what Habitual says about paths to executables, always code with the known path name.

Notice how you defined TUX_DIR within your script, that's also something you can do.

However if you run the tux.env and export variables you should be able to import those variables in your script using "import VAR"

jatal 05-22-2013 06:09 PM

another option :: alter path
 
Another option would be to alter the PATH defined in tux.env to ensure the psadmin executable is on the path.

If you find that is not working, echo $PATH before the command is executed to make sure the path is set as you expect. It is possible another script alters the path.

deep27ak 05-23-2013 02:15 AM

Quote:

Originally Posted by Habitual (Post 4956661)
try
Code:

/path/to/psadmin -p start  -d fin91dmo
/path/to/psadmin -c boot -d fin91dmo

in the script.

Hello I thought of using this but the thing is that particular command requires other env variables to be set as well.

So I decided to put the path of those variables in my .bash_profile and it is working.
Now when I start my machine the database gets up without any problem but the problem starts when we login to that user using putty or and client software the .bash_profile script runs again leading to run those commands for starting database :D

Well I knew about this consequence before using .bash_profile for setting up environment variable.

I tried to manually assign those variables in my script but I do not understand why it does not works.

Code:

# vi app.sh
#!/bin/bash

TUXDIR=/u01/Tuxedo/tuxedo10gR3
export TUXDIR
JAVA_HOME=/u01/peoplesoft/jre
export JAVA_HOME

PS_HOME=/u01/peoplesoft
sh $PS_HOME/psconfig.sh

psadmin -p start  -d fin91dmo
psadmin -c boot -d fin91dmo

Quote:

Originally Posted by pan64 (Post 4956667)
or try set -xv at the beginning of the script (as second line)

Can you please show me an example using my script as I had used "set" without any switches and it was not working

pan64 05-23-2013 02:42 AM

you can use this way:
Code:

#!/bin/bash
set -xv

TUXDIR=.....

or
bash -xv <your script>

this will produce an output about the running script and you will see what was happening.


All times are GMT -5. The time now is 12:29 AM.