LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to pass a variable from a called script back to the calling script (http://www.linuxquestions.org/questions/linux-general-1/how-to-pass-a-variable-from-a-called-script-back-to-the-calling-script-640082/)

steven.c.banks 05-05-2008 12: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:
....
fmfm_never_configured_count=0
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/get_fmfm_detail.sh $telephonenumber $fmfm_never_configured_count"
....

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

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 12: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:
Code:

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 02: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.

Thanks...


All times are GMT -5. The time now is 01:02 AM.