Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 05-05-2008, 12:09 PM   #1
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Rep: Reputation: 15
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 !!!
Old 05-05-2008, 12:40 PM   #2
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
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?
Old 05-05-2008, 02:00 PM   #3
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Original Poster
Rep: Reputation: 15
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
How to pass a c variable to a bash script? daYz Programming 3 09-28-2007 08:30 AM
cd keeps snapping back to current directory when called from bash script ghrellin Linux - General 5 08-28-2005 12:50 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration