#!/bin/bash
# Run local bash script on remote server via SSH connection
# Login variables
USER="username"
HOST="host_address" #Remote host
PATH_TO_SCRIPT="path/to/your_script.sh"
ssh -l $USER $HOST 'bash -s' < $PATH_TO_SCRIPT
## To run just a command on remote machine:
# COMMAND="echo 'Hi there!'"
# ssh -l $USER $HOST $COMMAND
## If you don't want to manually insert authentication password:
## Requires 'sshpass' locally (Debian-based systems: apt-get install sshpass)
## Note: This is a less secure way; You might want to use 'openssl' for password encryption and decryption
# PASSWD="your_password"
# sshpass -p $PASSWD ssh -l $USER $HOST 'bash -s' < $PATH_TO_SCRIPT