Unfortunately no one can be told what fun_plug is - you have to see it for yourself.
You are not logged in.
Hello,
I am trying to store the external ip of my NAS in en environment variables.
As far as I can see a simple export should do the work.
I can't get it work however. Could be it's too late for my brains to see the mistake:
I created a file called setMYIP.sh
#!/bin/sh #lookup the current ip of somehost.dyndns.org (managed by the WRT54G router) MYIP=`nslookup somehost.dyndns.org | tail -n 1 | awk '{print $3}'` echo $MYIP export MYIP
When I run ./setMYIP.sh I am getting the expected output:
root@NAS:/ffp/scripts# ./setMYIP.sh 1.2.3.4
But afterwards when I check the value of the MYIP variable, it's not set at all
root@NAS:/ffp/scripts# set | grep MY _=setMYIP.sh
I also tried the following, which didn't work either.
export MYIP=`nslookup somehost.dyndns.org | tail -n 1 | awk '{print $3}'`
export MYIP="1.2.3.4"
Enlighten me please
Last edited by Opperpanter (2011-02-20 23:45:07)
Offline
My shell scripting is quite rusty, but here goes. The script starts a new shell, and that environment ends when the script completes. You can use that variable elsewhere in that script and in scripts and commands called by the original script. But when the script ends, those variables also disappear.
I can guess two possible solutions:
1) if the script is used as a part of the startup, or the code in the fun_plug script, then that environment lasts as long as the device is on and may be inherited by other scripts. A caveat: I have read somewhere in these forums that some scripts on the NAS, or is it cron jobs scripts, may run in a different environment and thus is the cause of many a script headache.
2) have your script dump the ip address into a file (echo $MYIP > /ffp/etc/myip.txt) Have the script run on startup, and maybe as a cron job every x hours. Your other scripts can read in the file when needed.
Offline
neerav is right, when you run the script, it creates a new process that inherits it's environment from the process that ran it (the interactive shell, in this case). Changes to that process' environment won't be reflected in the interactive shell process' environment.
There is, however, a solution to that: run the script using '.', like so:
. ./setMYIP.sh
This will run the script in the current shell, without spawning a child process.
To learn more, see under Builtins here: http://linux.die.net/man/1/ash (you'll also find there what export does, and see why that didn't work).
Last edited by scaramanga (2011-02-21 10:55:52)
Offline