Bash – Can and how do you run a command on a remote server via a bash script

bashunix

I feel a little silly asking what would seem to be a Google-able question but I'm trying to script out a repetitive task of (1) ssh'ing into a remote server (2) running script.sh in my home directory, and (3) copy/pasting the output.

It would be great if I could write a script to do this work for me. I've written some bash scripts that scp files from these machines but never one that ran scripts on these machines.

Is it possible to have a script on machine 1 and log in and execute script.sh on machine 2 through machine n, dumping the output on machine 1? If so, how?

Best Answer

That's an easy one:

ssh user@host command

command = elaborate with piping and such as needed.

Related Topic