Skip to content

Instantly share code, notes, and snippets.

@abelcallejo
Last active July 18, 2019 22:41
Show Gist options
  • Save abelcallejo/62988be2a841ee901bafdfbedc910c4f to your computer and use it in GitHub Desktop.
Save abelcallejo/62988be2a841ee901bafdfbedc910c4f to your computer and use it in GitHub Desktop.
Executing commands on a remote server by using a local script

Executing commands on a remote server by using a local script

Shell

Sometimes you will need to execute commands on a remote server routinely but you don't want them to be scheduled. This material will guide you in doing it.

Prepared script

prepared_bash_script.sh - a sample bash/shell script that is in the local machine.

In the example it simply echos the first argument value when the script was executed.

Output

Hello world

Execution

executable.sh - a sample bash/shell script that calls for a canned/prepared script

In the example it simply executes the prepared_bash_script.sh by passing the argument Hello world. The prepared script will be executed on the server host and as user user.

#!/bin/bash
ssh -i key.pem user@host 'bash -s' < "prepared_bash_script.sh" "Hello world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment