0

I'm trying to make a script that uses variables from a remote script. Currently the script executes the remote script with an ssh user@server "/route/to/script.sh" command in the script. In that script I'm saving some variables. I wish to use these variables in my local script where I've began everything.

Any ideas how to do this?

Regards: Bert

7
  • 1
    The remote script needs to print the variable values, then the local script has to read the output and assign to its variables. Commented May 3, 2017 at 15:38
  • Can you show me the how-to, please? Commented May 3, 2017 at 15:39
  • Cheers Mate! Will go for it then. Commented May 3, 2017 at 15:42
  • 1
    One important thing to cover here -- how much do you trust the remote machine? Many of the approaches (particularly if you want to transfer multiple variables, and let the remote system choose their names) have substantial security caveats. It's safer to just treat your data as data, and not try to let the remote system control local variables as such. Commented May 3, 2017 at 15:42
  • 1
    Don't confuse data with variables. A variable is a name that refers to data; you want the data from the remote script, not the variable. Commented May 3, 2017 at 15:42

1 Answer 1

1

Lots of options possible. One could be:

a=$(ssh user@server "/route/to/script.sh")

While the remote script.sh looks something like this:

#!/bin/bash

hostname

This way, the output of the command hostname (should be the name of the remote host) will end up in the local variable a.

Sign up to request clarification or add additional context in comments.

1 Comment

I've done just the same. :) Thanks dude. upvoted it, but I haven't got enough rep, to mark it as an answer. Please do so yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.