I need to write a script that will SSH into a remote host, then run certain commands on that remote host, then exit. If I just do
ssh $host
#some command
the script will SSH in, wait until I manually exit, then run the commands.
How do I run those commands on the remote host?
SSH is also used to access local Bash scripts from a local or remote server. If you're looking for information on how to run multiple Linux commands in a Bash script, this article contains an extensive guide on how you can achieve this.
ssh $host 'command1; command2; command3'
or if you have just one command:
ssh $host command1
or if you have many commands (a script file):
cat file | ssh $host sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With