Created
June 7, 2023 09:32
-
-
Save dejanu/79197b6be8fc009529c3682f267a5306 to your computer and use it in GitHub Desktop.
Simple shell script that achieves concurrent SSH connections using background processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## ##################################################################### | |
## run concurrently command passed as argv on multiple remote servers ## | |
## UPDATE: servers array and user variable ## | |
######################################################################## | |
# define an array of remote servers | |
servers=("server1.fqdn" "server2.fqdn" "server3.fqdn") | |
# Function to execute command on a remote server | |
execute_command() { | |
server=$1 | |
command=$2 | |
# define USER for the ssh connection | |
ssh user@"$server" "$command" | |
} | |
for server in "${servers[@]}" | |
do | |
# exec arg command as background process | |
execute_command "$server" "$1" & | |
done | |
# wait for all background processes to complete | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment