I have 10 servers and I access them using jumpbox. I wrote a script for starting a service on each server. When I execute that script it's only run on one server and after pressing Ctrl+C it's executed on the next server and so on. I want to run it on all servers without pressing Ctrl+C.
This is my script:
#!/bin/bash
for i in `cat /etc/hosts | grep prod | awk '{print $2}'` ;
do
ssh $i "hostname && sudo service name start"
done;
sudo service name startwithout entering a password.-nto ssh and to end the command-line with&. As a last comment, you can replace the three sub-processescat /etc/hosts | grep prod | awk '{print $2}'with just one sub-processawk '/prod/ {print $2}' /etc/hosts.