2

I'm looking to, all in the course of one batch file:

  1. ssh into a remote computer
  2. execute commands (per the batch file) on the remote host.

What options do I need to add to the ssh invocation so that the batch file executes the lines following the ssh invocation over the connection?

e.g., with sftp it's simply adding a -b /dev/stdin and then << EOF at the end; how do I do this with SSH?

1 Answer 1

4

You can just run

ssh machine_name < batch_file.sh

to run all commands in batch_file.sh on machine_name. Works with at least OpenSSH. If you want to enter those commands by yourself before opening ssh, you can use

ssh machine_name << EOF
3
  • Awesome---is there a way to throw literal commands through the pipe? Commented Feb 17, 2011 at 20:14
  • Of course. You can use exactly same as with sftp; just write for example cat << EOF | ssh machine_name, write your commands and press ctrl+D (EOF) Commented Feb 17, 2011 at 20:16
  • 1
    Here's a Useless Use of cat Award for you. (ssh < batch_file.sh and ssh <<EOF) Commented Feb 17, 2011 at 21:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.