GNU Parallel and sshpass with server list in a loop
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
With this loop we sequential update on all servers (server list = consul members | grep awk 'print $2' | cut -d ":" -f1
) the package consul
.
for i in $(consul members | grep awk 'print $2' | cut -d ":" -f1) ; do sshpass -p $PASSWORD ssh -oStrictHostKeyChecking=no -q root@$i "hostname && yum clean all && yum -y update consul && systemctl restart consul.service" ; done
We have over 1000 servers, so we wish to run the sshpass
in parallel on 10 servers. I found GNU Parallel for this task.
Howo use it with sshpass
and make sure no server (server list) is done twice?
shell-script openssh gnu-parallel
add a comment |Â
up vote
1
down vote
favorite
With this loop we sequential update on all servers (server list = consul members | grep awk 'print $2' | cut -d ":" -f1
) the package consul
.
for i in $(consul members | grep awk 'print $2' | cut -d ":" -f1) ; do sshpass -p $PASSWORD ssh -oStrictHostKeyChecking=no -q root@$i "hostname && yum clean all && yum -y update consul && systemctl restart consul.service" ; done
We have over 1000 servers, so we wish to run the sshpass
in parallel on 10 servers. I found GNU Parallel for this task.
Howo use it with sshpass
and make sure no server (server list) is done twice?
shell-script openssh gnu-parallel
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
With this loop we sequential update on all servers (server list = consul members | grep awk 'print $2' | cut -d ":" -f1
) the package consul
.
for i in $(consul members | grep awk 'print $2' | cut -d ":" -f1) ; do sshpass -p $PASSWORD ssh -oStrictHostKeyChecking=no -q root@$i "hostname && yum clean all && yum -y update consul && systemctl restart consul.service" ; done
We have over 1000 servers, so we wish to run the sshpass
in parallel on 10 servers. I found GNU Parallel for this task.
Howo use it with sshpass
and make sure no server (server list) is done twice?
shell-script openssh gnu-parallel
With this loop we sequential update on all servers (server list = consul members | grep awk 'print $2' | cut -d ":" -f1
) the package consul
.
for i in $(consul members | grep awk 'print $2' | cut -d ":" -f1) ; do sshpass -p $PASSWORD ssh -oStrictHostKeyChecking=no -q root@$i "hostname && yum clean all && yum -y update consul && systemctl restart consul.service" ; done
We have over 1000 servers, so we wish to run the sshpass
in parallel on 10 servers. I found GNU Parallel for this task.
Howo use it with sshpass
and make sure no server (server list) is done twice?
shell-script openssh gnu-parallel
shell-script openssh gnu-parallel
edited Aug 2 '16 at 15:21
ams
4,2521123
4,2521123
asked Jun 24 '16 at 12:49


Ivanov
4782823
4782823
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
Indeed, pssh
sounds like the better solution. If you must use parallel
it should be fairly simple: pipe the hostnames one per line into a single command that uses as a placehold. Eg:
consul members | ... awk 'print $2' | cut -d ":" -f1 |
parallel -j 10 sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -q root@ "hostname && yum clean all && yum -y update consul && systemctl restart consul.service"
Using sshpass
should not make any difference. Test it first with a simple command such as just hostname
.
add a comment |Â
up vote
2
down vote
Use pssh with ssh host key authentication it's better
first, on the local box, as the user to connect with, do ssh-keygen to create a public key
then use ssh-copy-id to copy that public key to all the remote servers. then do sometinhg like:
pssh -h <(consul members | grep awk 'print $2' | cut -d ":" -f1) -o /tmp/update-consul-servers -i "yum clean all && yum -y update consul && systemctl restart consul.service"
add a comment |Â
up vote
0
down vote
All, this is the working shell that prompt password in the script, do the require command and list which server is not authenticated.
for i in cat /root/fahmi/up.list
;
do
if ! sshpass -p 'password' ssh -n -T -o StrictHostKeyChecking=no user@"$i";
then
echo "Server $i not accessible";
fi
sshpass -p 'password' ssh -T -o StrictHostKeyChecking=no user@"$i" <./command.sh
done
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Indeed, pssh
sounds like the better solution. If you must use parallel
it should be fairly simple: pipe the hostnames one per line into a single command that uses as a placehold. Eg:
consul members | ... awk 'print $2' | cut -d ":" -f1 |
parallel -j 10 sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -q root@ "hostname && yum clean all && yum -y update consul && systemctl restart consul.service"
Using sshpass
should not make any difference. Test it first with a simple command such as just hostname
.
add a comment |Â
up vote
3
down vote
accepted
Indeed, pssh
sounds like the better solution. If you must use parallel
it should be fairly simple: pipe the hostnames one per line into a single command that uses as a placehold. Eg:
consul members | ... awk 'print $2' | cut -d ":" -f1 |
parallel -j 10 sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -q root@ "hostname && yum clean all && yum -y update consul && systemctl restart consul.service"
Using sshpass
should not make any difference. Test it first with a simple command such as just hostname
.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Indeed, pssh
sounds like the better solution. If you must use parallel
it should be fairly simple: pipe the hostnames one per line into a single command that uses as a placehold. Eg:
consul members | ... awk 'print $2' | cut -d ":" -f1 |
parallel -j 10 sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -q root@ "hostname && yum clean all && yum -y update consul && systemctl restart consul.service"
Using sshpass
should not make any difference. Test it first with a simple command such as just hostname
.
Indeed, pssh
sounds like the better solution. If you must use parallel
it should be fairly simple: pipe the hostnames one per line into a single command that uses as a placehold. Eg:
consul members | ... awk 'print $2' | cut -d ":" -f1 |
parallel -j 10 sshpass -p "$PASSWORD" ssh -oStrictHostKeyChecking=no -q root@ "hostname && yum clean all && yum -y update consul && systemctl restart consul.service"
Using sshpass
should not make any difference. Test it first with a simple command such as just hostname
.
answered Jun 24 '16 at 19:06


meuh
30.6k11753
30.6k11753
add a comment |Â
add a comment |Â
up vote
2
down vote
Use pssh with ssh host key authentication it's better
first, on the local box, as the user to connect with, do ssh-keygen to create a public key
then use ssh-copy-id to copy that public key to all the remote servers. then do sometinhg like:
pssh -h <(consul members | grep awk 'print $2' | cut -d ":" -f1) -o /tmp/update-consul-servers -i "yum clean all && yum -y update consul && systemctl restart consul.service"
add a comment |Â
up vote
2
down vote
Use pssh with ssh host key authentication it's better
first, on the local box, as the user to connect with, do ssh-keygen to create a public key
then use ssh-copy-id to copy that public key to all the remote servers. then do sometinhg like:
pssh -h <(consul members | grep awk 'print $2' | cut -d ":" -f1) -o /tmp/update-consul-servers -i "yum clean all && yum -y update consul && systemctl restart consul.service"
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Use pssh with ssh host key authentication it's better
first, on the local box, as the user to connect with, do ssh-keygen to create a public key
then use ssh-copy-id to copy that public key to all the remote servers. then do sometinhg like:
pssh -h <(consul members | grep awk 'print $2' | cut -d ":" -f1) -o /tmp/update-consul-servers -i "yum clean all && yum -y update consul && systemctl restart consul.service"
Use pssh with ssh host key authentication it's better
first, on the local box, as the user to connect with, do ssh-keygen to create a public key
then use ssh-copy-id to copy that public key to all the remote servers. then do sometinhg like:
pssh -h <(consul members | grep awk 'print $2' | cut -d ":" -f1) -o /tmp/update-consul-servers -i "yum clean all && yum -y update consul && systemctl restart consul.service"
answered Jun 24 '16 at 13:37
Gregg Leventhal
2,884114174
2,884114174
add a comment |Â
add a comment |Â
up vote
0
down vote
All, this is the working shell that prompt password in the script, do the require command and list which server is not authenticated.
for i in cat /root/fahmi/up.list
;
do
if ! sshpass -p 'password' ssh -n -T -o StrictHostKeyChecking=no user@"$i";
then
echo "Server $i not accessible";
fi
sshpass -p 'password' ssh -T -o StrictHostKeyChecking=no user@"$i" <./command.sh
done
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
All, this is the working shell that prompt password in the script, do the require command and list which server is not authenticated.
for i in cat /root/fahmi/up.list
;
do
if ! sshpass -p 'password' ssh -n -T -o StrictHostKeyChecking=no user@"$i";
then
echo "Server $i not accessible";
fi
sshpass -p 'password' ssh -T -o StrictHostKeyChecking=no user@"$i" <./command.sh
done
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
All, this is the working shell that prompt password in the script, do the require command and list which server is not authenticated.
for i in cat /root/fahmi/up.list
;
do
if ! sshpass -p 'password' ssh -n -T -o StrictHostKeyChecking=no user@"$i";
then
echo "Server $i not accessible";
fi
sshpass -p 'password' ssh -T -o StrictHostKeyChecking=no user@"$i" <./command.sh
done
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
All, this is the working shell that prompt password in the script, do the require command and list which server is not authenticated.
for i in cat /root/fahmi/up.list
;
do
if ! sshpass -p 'password' ssh -n -T -o StrictHostKeyChecking=no user@"$i";
then
echo "Server $i not accessible";
fi
sshpass -p 'password' ssh -T -o StrictHostKeyChecking=no user@"$i" <./command.sh
done
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 8 mins ago


Muhamad Fahmi AM
1
1
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Muhamad Fahmi AM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f291847%2fgnu-parallel-and-sshpass-with-server-list-in-a-loop%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password