LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-20-2015, 01:55 AM   #1
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Rep: Reputation: 0
variable from remote script to local script


Hi,

I have written a script for memory management at remote machine.
Scenario is like:
1. SSH will read details from prop file of server to connect.
2. Then set node variable in script.
3. scp the script to remote machine.
4. Run memory management commands on remote machine.
5. send back the variable to local machine with memory info in integer.
6. I will pass the info to script to create files based on the integer provided.

I'm successful doing this above steps at local machine.
My problem is with passing the calculated memory as variable back to local machine. So my issue made me stuck at point 5.

how i can pass the variable back to script in the same session or same running shell.

Thanks...
 
Old 10-20-2015, 01:59 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Please show us your code so far - there are many possible solns.
 
Old 10-20-2015, 02:13 AM   #3
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Here it is:

Code:
sshpass -p 'password' scp /usr/tst/server1/meminfo.sh user@host:/tmp/server2
sshpass -p 'password' ssh user@host 'bash -s' < /usr/tmp/server2/meminfo.sh

#Want to expect the output from meminfo.sh from remote machine here
#what I thoughtt here to save in file and read the file for further steps.
#but i want to receive that information as variable here. like
var=<integer from remote>

further code to create empty files based on the var value
end
 
Old 10-20-2015, 02:16 AM   #4
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Do i need to put some logic in meminfo to get the variable set or changes with local script?
 
Old 10-20-2015, 02:21 AM   #5
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Original Poster
Rep: Reputation: 0
I think I just thought a solution :
correct me if wrong:
var=$(sshpass -p 'password' ssh user@host 'bash -s' < /usr/tmp/server2/meminfo.sh)

echo $var

Hope its right way to do

THanks
 
Old 10-20-2015, 02:29 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Looks about right, (I don't have sshpass installed), BUT I would highly recommend using ssh-keys instead of passwds for scripts.
 
Old 10-20-2015, 02:34 AM   #7
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Original Poster
Rep: Reputation: 0
I will go finally with ssh-keys only. this is right now for testing only.

chrism01: Is there any way I can pass variable from remote meminfo.sh script back to local script.
means I'll calculate memory in remote script setting as a variable n then sending back the variable value back to local. instead of using this new variable and putting ssh under it?
 
Old 10-20-2015, 07:53 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Here's a quick 'n dirty test I ran
Code:
# A=$(ssh vm4 ./t.sh)
# echo $A
VALUE
& 'VALUE' is the o/p of the remote test script
Code:
echo VALUE

HTH
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] replace local value variable with new value from script Bharath_ Linux - Newbie 2 05-22-2013 12:02 PM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 05:50 PM
bash - start remote script from local script? babag Programming 7 04-06-2008 06:46 PM
clamd upgradation in remote mach through local mac by script to be run on local mach Narayandutt Programming 3 11-29-2006 11:00 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 08:20 AM


All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration