troubleshooting Question

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

Avatar of alexatsearidge
alexatsearidgeFlag for Canada asked on
Shell ScriptingLinux Distributions
5 Comments1 Solution1469 ViewsLast Modified:
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:


export LOGFILE
export PATH
export BIN

   if su - myuser -c "$DIBIN" >>$LOGFILE 2>&1 &; then


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.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros