Question : Linux init script, bash, exporting variable and accessing as another user?

I'm using Fedora 8.

I have an initscript for my app which sets some variables, and then starts the process as another user. ex:

LOGFILE=/usr/local/code/myprog/logfile.txt
PATH=$PATH:/usr/local/code/myprog/
BIN="myprog"

export LOGFILE
export PATH
export BIN

   if su - myuser -c "$DIBIN" >>$LOGFILE 2>&1 &; then
       success
   else
       failure
   fi

   echo


The problem as I understand it is that my app cannot then access the variables, since they were set by root. My app, in C++, uses the getenv("LOGFILE") to check for the variable, which returns null.

I'm looking for a solution that involves the least amount of system configuration (ie., editing sudoers or bash profiles). Hopefully something can work right in the script. I'm thinking there should be a way that I can export variables for all users to read, but I don't quite understand the environment enough at this point.

Thanks.

Answer : Linux init script, bash, exporting variable and accessing as another user?

try to put the command you want to execute under different user in a script where you set variables then you call the script with the su command
Random Solutions  
 
programming4us programming4us