You are not logged in.

#1 2007-10-15 20:59:11

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Can one set an environment variable globally

I am running a script in v/c 2 that looks like this:

#!/bin/bash 
TURNEDON=1
until [ 6 -eq 9 ]; do
  if [ $TURNEDON -eq 0 ]; then
    poweroff
  else
    sleep 5
  fi
done

The idea is, it checks to see if TURNEDON has become 0 every 5 seconds and if so, turns off the computer.  I would like to be able to shutdown by setting TURNEDON=0 in v/c 1.

The problem is, whenever I run TURNEDON=0, set TURNEDON=0, env TURNEDON=0 or export TURNEDON=0, this script will still see it as a 1 because I have not set TURNEDON=0 globally.  Is there any command or series of steps to change the value of TURNEDON to 0 such that every process (or at least this script) will inherit it?

Last edited by ConnorBehan (2007-11-09 18:35:42)


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#2 2007-10-15 23:24:48

kumico
Member
Registered: 2007-09-28
Posts: 224
Website

Re: Can one set an environment variable globally

/etc/profile

Offline

#3 2007-10-15 23:31:09

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Can one set an environment variable globally

kumico wrote:

/etc/profile

No, I don't believe that would do... He wants to change the environment of a running process.

I too have been wondering if this is possible. (The only thing I found out was printing the environment of a running process 'ps auxwwe | grep processname')

Offline

#4 2007-10-15 23:35:46

nj
Member
Registered: 2007-04-06
Posts: 93

Re: Can one set an environment variable globally

I'm not sure if you can set an env variable globally, but you can use a file instead.

#!/bin/bash 
until [ 6 -eq 9 ]; do
  TURNEDON=`cat ~/.poweroff`
  if [ "$TURNEDON" = "0" ]; then
    echo 1 > ~/.poweroff
    poweroff
  else
    sleep 5
  fi
done

Then 'echo 0 > ~/.poweroff' to poweroff.

Offline

#5 2007-10-15 23:39:33

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: Can one set an environment variable globally

Oh I see... so instead of checking if TURNEDON=0 (in which case it check's its own environment) I'd use 'ps auxwwe | grep processname' to check if I have set TURNEDON=0 in some other process's environment.  I think for my purposes it would be much easier to work with files for this.  The script now looks like this.

#!/bin/bash 
rm /home/dummy
until [ 6 -eq 9 ]; do
  if [ -e /home/dummy ]; then
    poweroff
  else
    sleep 5
  fi
done

And to shutdown I simply run touch /home/dummy.  After using this method several times I may have some claim as to why I like it better than a normal shutdown lol.


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#6 2007-11-09 18:37:18

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: Can one set an environment variable globally

I am again in a situation where I'm trying to find how to change a process' environment.  In this case it is xfce4-panel because I want to change the anchor points of the panel when I change workspaces.  There is a GUI to do this quickly, but the code that happens when you click the button, isn't a shell command, it's a series of C functions and GTK API calls that I don't know how to script... so I'm trying to trick xfce4-panel into thinking I clicked the button by changing variables.


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#7 2007-11-09 22:27:21

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: Can one set an environment variable globally

you cannot change an environmental variable "globally" in all running processes at once.

Offline

#8 2007-11-10 08:46:30

colinzhengj
Member
From: Cambridge, MA
Registered: 2007-03-20
Posts: 23
Website

Re: Can one set an environment variable globally

ConnorBehan wrote:

I am again in a situation where I'm trying to find how to change a process' environment.  In this case it is xfce4-panel because I want to change the anchor points of the panel when I change workspaces.  There is a GUI to do this quickly, but the code that happens when you click the button, isn't a shell command, it's a series of C functions and GTK API calls that I don't know how to script... so I'm trying to trick xfce4-panel into thinking I clicked the button by changing variables.

There is no clean way to do so. Best bet is to patch source code of xfce4-panel

Offline

Board footer

Powered by FluxBB