1

I know about /etc/profile and /etc/environment, but I would like to set a global environmental variable after boot and login. By global, I mean an environment variable that can be accessed by any program (running under the current user).

Basically at any given point, say 10 minutes after boot, I would like to be able to run a script that would set some global environment variables. Is this possible?

Background

I am having some trouble with gpg-agent in Ubuntu 14.04. Programs use environmental variables to connect to the gpg-agent process. My trouble is with multiple instances of gpg-agent running (only one of which has ssh-support enabled). I would like to be able to kill all existing instances of gpg-agent and start a new one with ssh-support. However, for other programs to be able to access the new instance, I need the environmental variables to be made global. Doing it during startup hasn't worked for me since the other gpg-agent seems to start after mine, replacing the environmental variables.

5
  • You can't run a script that will magically inject environment variables into running processes. Would running a script that creates a config file that other processes can read help? May 6, 2014 at 19:56
  • Why not use a file? The behaviour you want isn't easily achievable. Using a file seems like an elegant solution
    – ek9
    May 6, 2014 at 19:56
  • A file sounds great, but I don't think it will work in my situation since the programs are looking for predefined environmental variables.
    – Daniel
    May 6, 2014 at 20:08
  • This looks like it might work for you,but it requires that the given application uses a particular pam module stackoverflow.com/a/1641569/486399 May 6, 2014 at 21:29
  • 1
    This is an XY problem: your real problem is that gpg-agent is not configured properly, and you think that the solution is to set an environment variable visible to all processes.
    – chepner
    May 7, 2014 at 13:34

1 Answer 1

0

Sometimes I face a closely related problem. I have an ssh-agent running on a machine under the umbrella of its graphical desktop, but I access the same machine remotely. That shell doesn't have the environment variables.

For that I use a script which looks through /proc for Bash processes, and scrapes through their /proc/<pid>/environ entries, looking for SSH_AGENT_PID and SSH_AGENT_SOCK variables. Then it re-creates these entries in shell syntax, so this whole "env scraping script" can be eval-ed in the new shell.

Basically, "go through /proc to find what other Bash-es are using for their agent variables and reproduce that in this session".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .