Run (multiple) commands on remote servers via ssh

Here’s a quick way to login to servers to run some commands which is particularly handy when you have to do it on many servers..

ssh user@server ‘command1;command2;’

Or  to execute a remote command interactively use “-t” like so..

ssh -t user@server command

Here’s some simple examples..

ssh user@server crontab -l
ssh -t user@server crontab -e

No doubt you can guess from that how to easily run commands on multiple servers in one go.. just bung all the server addresses in a script and loop through them with whatever commands you want to run on each. Of course you’d probably want to have them all setup for login with key rather than password unless you want to make your script all fancy and send user/pass on request each time.

 

You may also like...