HowTo: Execute A Script On Remote UNIX / Linux Server

HowTo: Execute A Script On Remote UNIX / Linux Server

There are several ways to execute a script on a remote Unix/Linux server. Here are a few options:

  1. Use ssh to log in to the remote server and run the script directly:
refer t‮:o‬lautturi.com
ssh user@remote-server 'bash -s' < local-script.sh

This will log you in to the remote server as the user user and run the local-script.sh script on the remote server.

  1. Use scp to copy the script to the remote server, and then use ssh to log in and run the script:
scp local-script.sh user@remote-server:~/
ssh user@remote-server 'bash ~/local-script.sh'

This will copy the local-script.sh script to the home directory of the user user on the remote server, and then log you in to the remote server and run the script.

  1. Use rsync to copy the script to the remote server, and then use ssh to log in and run the script:
rsync local-script.sh user@remote-server:~/
ssh user@remote-server 'bash ~/local-script.sh'

This is similar to the previous method, but rsync has the advantage of only transferring the parts of the file that have changed, which can be faster if the script is large.

Keep in mind that you will need to have the correct permissions and access to the remote server in order to execute the script.

Created Time:2017-10-16 14:38:51  Author:lautturi