How to run local shell script on remote server via SSH?
ssh user@remotehost "bash -s" < local_script.sh
-s
makes bash read from standard input.
If you need to pass arguments to your script:
ssh user@remotehost "bash -s" -- < local_script.sh "your_arg" "--aswitch" "avalue"
Note the double dash --
(signifying the end of the command options) and the quotes around the arguments.
phoibos answer is the working for me.
ssh user@remotehost "bash -s" < local_script.sh
But you have to be sure that your script explicitly call exit or you will stay logged to the remote server after the script execution.
To be short, do not forget to put this at the end of local_script.sh
:
exit 0