Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute one-line ssh command with variable from local environment

Tags:

unix

ssh

Let's pretend that in the current shell, I have a variable.

$ echo $MY_VAR
$ 2

What I want is to pass the value of this variable to an argument of a command I'm executing through ssh, like:

ssh -i /ebs/keys/test [email protected] '/some/command -<here_i_want_to_have_value_of_$MY_VAR_variable>'

Thanks!

like image 938
Anton Koval' Avatar asked Oct 11 '11 12:10

Anton Koval'


People also ask

How do you ssh into the environment?

This can be found by pressing the windows key and typing command prompt and hitting enter. The ssh syntax is ssh username@destation and then hitting enter and supplying your password. In this case your username will be your hawkID and your password.


1 Answers

Assuming you cannot use double quotes around the entire command to ssh, you could break just $MY_VAR out like this:

ssh -i /ebs/keys/test [email protected] '/some/command -'"$MY_VAR"

If the rest of the command to ssh does not contain tokens that will be interpreted within double quotes, you can enclose the entire command in double quotes instead of single.

like image 77
Kurt Stutsman Avatar answered Sep 30 '22 06:09

Kurt Stutsman