I've got two local files, one config.sh
that contains variable definitions, another script.sh
that contains a bash script.
Locally, I can do:
source config.sh; bash script.sh
I'm looking for the same thing via ssh, so far I got this working:
ssh user@host 'bash -s' < script.sh
But I'm not sure if I should use cat
or some input pipes <(...)
to get both config.sh & script.sh to be executed.
What would be the best, clean way to execute multiple commands that require some content to be piped in with ssh?
Assuming both scripts are on the local host, not the remote host:
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.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.
http://kahimyang.info/kauswagan/howto_blogs/704-using_expect_script_to_automate_ssh_logins_and_do_routine_tasks_accross_multiple_hosts