I want to create a script that detects what network my laptop is on and sets a few things, but I have run into a few problems:
1. what is the "right" way to run this? I can make it a executable file, but then I would have to manually run it each time... Could it be made a daemon? The scripts in /etc/rc.d/ seems simple enough for me to copy .. but is this "right"?
2. I need to export the variables http_proxy and ftp_proxy, how can I do that for a script? If I just use a export statement, the variables is only in the scope of the script itself...
I hope I can get some help with this...
I think the right way to do this is make you script executable and place it in /usr/local/bin then make a daemon and let it stop/start you script
I don't know excacly what you mean with export, I thinkit just works, for instance try this:
export var=blabla ./script2
The export command will set the variable for that login. So in that script and all other programs/script it calls the exported var will be readable. But if you login again (start for instance a new terminal) you have to export it again thats why a lot of exports are in the file ~/.bashrc so they are exported on every 'login'
the export will work/notwork depending on how your script is called. If it is called and spawns an external shell (most scripts do this) then the export will indeed not remain for any subsequent scripts.
If you need the values for something universal, consider adding it to a script that gets sourced on startup (/etc/profile), create an /etc/profile.d/foo file and add it there, or create a seperate file somewhere else and have each script needing that value source it. (. /script)
Hope that helps a bit..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍