1

I want to write a shell script to run on a Mac OS system that will do something along the lines of the following:

  • SSH into a Linux server (using key authentication)
  • Perform a command on the server via SSH

I would assume it'd be something like this:

ssh user@ip --[some kind of key auth flag here]
command --whatever-flags-here

Unfortunately, I don't have a Mac nor do I have any experience using them at all so I'm hoping you guys can help me out with this one.

2

1 Answer 1

0

You can do it like this:

ssh user@ip [ssh-options] "command1; command2; command3; ..."

For example:

ssh user@ip "touch test.txt; cp test.txt test2.txt"

will create the two empty files test.txt and test2.txt on the remote machine.

Another approach would be to use a stdin redirection

ssh user@ip [ssh-options] < your_commands.sh

where your_commands.sh is the script that will executed on the remote machine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.