24

I have a script that exports an environment variable and starts some subscripts.

export LOGLEVEL="1" /home/myuser/bin/myscript1.sh /home/myuser/bin/myscript2.sh 

LOGLEVEL is available to the processes started from the subscripts. How can I change the environment variable LOGLEVEL?

I have tried to set the variable with export LOGLEVEL="5" but that`s not working.

8
  • possible duplicate of Is there a way to change another process's environment variables? Commented Dec 21, 2011 at 11:42
  • Where do you want the LOGLEVEL changed and for what process - as you state it has changed for the two myscript processes. Commented Dec 21, 2011 at 11:46
  • @Mark: It doesn't matter if LOGLEVEL is changed for the processes of both subscripts, or if I can change it for individual processes. Essentially I'm looking for any working way talking to a process, that it should print more information into it's logfile. Commented Dec 21, 2011 at 11:56
  • @ChristianAmmer - then you need to show us how you use LOGLEVEL in the scripts Commented Dec 21, 2011 at 11:58
  • @Mark: Sorry that I wasn't accurate enough, but LOGLEVEL is only exported in the script, it is used from the processes through getenv(). Commented Dec 21, 2011 at 12:03

1 Answer 1

30

In general, you can only influence a process's environment variables at the time the process starts up. If you need to communicate a change to a running process, the environment isn't the right tool.

However, this question has some answers that suggest ways to overcome this limitation.

Edited to add in light of discussion in the question's comments: A fairly good way of communicating occasionally changing setup to a running process is to designate a configuration file where the LOGLEVEL value is set, send a SIGHUP to the process, and have the process reread the configuration file upon receipt of SIGHUP.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the link and the clue how to manage this in the right way – I have read more about SIGHUP and found on Wikipedia: Daemon programs sometimes use SIGHUP as a signal to restart themselves, the most common reason for this being to re-read a configuration file which has been changed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.