Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got two local files, one that contains variable definitions, another that contains a bash script.

Locally, I can do:

source; bash

I'm looking for the same thing via ssh, so far I got this working:

ssh user@host 'bash -s' <

But I'm not sure if I should use cat or some input pipes <(...) to get both & to be executed.

What would be the best, clean way to execute multiple commands that require some content to be piped in with ssh?

share|improve this question
ssh user@host "source; bash" (put commands inside "" ) - does this answer your question? – Tim Haegele Apr 9 '13 at 13:44
Are you wanted to run your config script on the remote machine, then use the output and run on the remote machine with some output that the config script generates? – tdk2fe Apr 9 '13 at 13:46

Assuming both scripts are on the local host, not the remote host:

cat | ssh -T remote_host bash

You may want to use the '-t' flag if instead if you wish to force pseudo-TTY allocation on the remote end. The local SSH process wont't have one since you stdin is from a pipe. You only need to add the string "bash" to the end of the command line if that is not the default shell on the remote end. Also, note that your original code wouldn't work unless your "variable definitions" export the environment variables in question.

share|improve this answer

Use EXPECT to run your scripts from your remote machine, that way your scripts are executed as if they are in your local machine. Here is a short demonstration on how to use EXPECT.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.