I am writing a script that connects to multiple servers which uses 3 different users.
#!/bin/ksh
server1=("abc1" "abc2")
server2=("abc3" "abc4")
server3=("abc5" "abc6")
for i in "${server1[@]}"
do ssh sam@$i "some command"
done
for i in "${server2[@]}"
do ssh danny@$i "some command"
done
for i in "${server3[@]}"
do ssh robert@$i "some command"
done
Is there a way to combine all three for
loops` into just one. Actually I want just want to write just one ssh for multiple connections.
I have tried putting all servers in 1 array and users in anotherlike
servers=("abc1" "abc2" "abc3" "abc4" "abc5" "abc6")
users=("sam" "Danny" "Robert")
for i in ${servers[@]}
do
ssh ${users[@]}@$i "some command"
done
But this way the script puts each user with each server, which ends up locking the service accounts…
What I want is some script that loops all the servers and users and only match user Sam
with array server1
user danny
with array server2
and user robert
with array server3
only.
is there a better way to match just the right user with right server in a clean and better way…