JeffCharter
JeffCharter

Reputation: 1549

passing an argument to a bash script that is run by redirecting to bash

I am trying to either pass an argument or set a variable for a bash script that gets executed remotely. Part of the trouble is that server I am ssh-ing into does a chroot after connection. The only way I have found to execute a script looks like this:

ssh user@server 'bash -ex' <  /tmp/script

I have a need for a variable in that script. It doesn't matter if it is an arg or a environment variable passed to bash somehow. The only way I can think of to solve this problem is by doing something like:

sed -e s/VAR/VAR=dog/g /tmp/script > /tmp/replaced
ssh user@server 'bash -ex' < /tmp/replaced

I think it's obvious why I don't like that solution. Is it possible to do what I want?

Upvotes: 1

Views: 309

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

If you configure SendEnv (client) and AcceptEnv (server) properly, you can have ssh send the variable for you.

VAR=dog ssh user@server 'bash -ex' < /tmp/replaced

Upvotes: 2

Related Questions