1

I have a script.sh stored on remote server at some directory, which I want to run from a local computer.

How can I do that in unix using ssh?

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109
Komal
  • 41
  • 1
  • 4

2 Answers2

5

You can use ssh command from the local server to execute commands on the remote server. You just have to do something like this:

ssh [user]@[server] '[command]'

In your case, you are trying to execute a shell-script. You can use the same method in the following way:

ssh [user]@[server] /location/of/your/script.sh

You can also run multiple commands in this way:

ssh [user]@[server] '[command 1]; [command 2]; [command 3]'

Or you can also do something like this:

ssh [user]@[server] << EOF
command 1
command 2
command 3
EOF
iqstatic
  • 2,322
  • 3
  • 21
  • 39
  • is it possible to pass file from the local pc as input. Consider the simple case with `cat` `ssh user@server 'cat' local_file`. i.e. use the cat from the remote pc to display file from the local pc. – Alexander Cska Jul 11 '19 at 14:52
0

I assume you have ssh access to your remote server. Type this in a terminal at the local server:

ssh user@remote-server /path/to/script.sh
chaos
  • 8,162
  • 3
  • 33
  • 40