Link to home
Start Free TrialLog in
Avatar of Julie Kurpa
Julie KurpaFlag for United States of America

asked on

Linux: Unable to pass variables to shell script using "su - xxxx"

I'm working in Oracle Linux 7.   We are moving to this environment from AIX and I'm trying to run the shell scripts in Linux that worked fine in AIX.

One of the scripts passes variables to another shell script by doing "su - oracle" so that the called script will run in Oracle's environment since it does sqlplus to the database to execute a procedure.

For some reason, when using the "su - oracle", the variables do not get passed.  Grrrr

The calling script, named "read_log", is executed by root and passes the variables this way:

#!/bin/bash
 su - oracle -c /dbscripts/run_SQL_insert_proc $UOWNER $UTABLE_NAME $UCOLUMN_NAME $COLUMN_VALUE

The called script, named "run_ora_proc" is owned by oracle and does the sqlplus.   I do an "echo" at the beginning of the script but the variables are empty.  The $0 does show the script name though.

#!/bin/bash
echo "passed variables are " "$0" "$1" "$2" "$3" "$4"

Screen output is:

passed variables are  /dbscripts/run_ora_proc

The shell environment for both root and oracle users is "bash".

What am I doing wrong?
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

You need to check the AIX system and see what sets: $UOWNER $UTABLE_NAME $UCOLUMN_NAME $COLUMN_VALUE

I'm not an AIX person but those don't look like system generated variables.  They look user-defined.
Avatar of Julie Kurpa

ASKER

You are correct that they are user defined.   I am setting them in the calling script.  

They are indeed being set because I echo them just before calling the next script with the "su - oracle" that I pasted.  

If I don't use the "su - oracle" when calling the next script, the variable get passed just fine.  I believe it's because I'm staying in root's shell rather than changing to Oracle's shell environment.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
YES!!   That did it!!   Joy Joy Joy!   Thank you Slighwv.  You are awesome!