LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-05-2008, 12:09 PM   #1
steven.c.banks
Member
 
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:
....
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 !!!
 
Old 05-05-2008, 12:40 PM   #2
beadyallen
Member
 
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:
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?
 
Old 05-05-2008, 02:00 PM   #3
steven.c.banks
Member
 
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.

Thanks...
 
  


Reply


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


All times are GMT -5. The time now is 10:58 PM.

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