You can usually do a for
loop with ssh
without problems.
$ for srv in 192.168.88.138; do echo $srv:; ssh $srv uptime; done
192.168.88.138:
13:27:25 up 30 days, 8:42, 1 user, load average: 4.15, 4.06, 4.06
So in this case I ran uptime
on the other side. You can replace uptime
with what you want to run. Whatever you put there is where the exit needs to be. uptime
exits once it prints its output, but if you are writing the script you may need to make sure it eventually exits so the for
loop can continue.
If you're doing anything complicated I'd recommend creating the script in a separate file and then scp
ing it to the server you want to run it on then ssh in to run it. Trying to get something complicated into ssh via quoting and escapes is more challenging than it is worth usually.
I've done this hundreds of times and it works fine when you want things to run on one server at a time. If you want things to run in parallel there are other options, but I'd look at ansible first.