-   Linux - General (
-   -   how to pass a variable from a called script back to the calling script (

steven.c.banks 05-05-2008 01:09 PM

how to pass a variable from a called script back to the calling script
I am working on a script which calls another script on a different server. I need to return variables from the called script back to the calling script.

Calling script:
export fmfm_never_configured_count
telephonenumber=`echo $line | cut -f2 -d":"`
# Use ssh -n to make sure loop continues
ssh -n root@$mss_server "/root/robert/ $telephonenumber $fmfm_never_configured_count"

Called script:
if [ "$fmfm_configured" = "" ];
fmfm_never_configured_count=`expr $fmfm_never_configured_count + 1`

fmfm_never_configured_count is incremented correctly, but is not passed back to the calling script. Any help would be much appreciated !!!

beadyallen 05-05-2008 01:40 PM

You're not going to get it working directly (since you won't be able to 'source' scripts that aren't 'local', but why not pass the result through standard output. For example, call you ssh line like:

result=`ssh root@$mss_server "/root/robe....`
and have the last bit of your 'called' script print out the current value of the fmfm_never_configured_count variable.

Would that work in your situation?

steven.c.banks 05-05-2008 03:00 PM

Unfortunately this won't work because other lines are written to standard output by the called script. However, I found that I can tail stdout when I return to the the calling script, and get what I need, so your suggestion was helpful and steered me in the right direction.


All times are GMT -5. The time now is 05:53 AM.