GNU Parallel and sshpass with server list in a loop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












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?










share|improve this question



























    up vote
    1
    down vote

    favorite
    1












    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?










    share|improve this question

























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 2 '16 at 15:21









      ams

      4,2521123




      4,2521123










      asked Jun 24 '16 at 12:49









      Ivanov

      4782823




      4782823




















          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.






          share|improve this answer



























            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"





            share|improve this answer



























              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





              share








              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.

















                Your Answer







                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: false,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                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






























                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.






                share|improve this answer
























                  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.






                  share|improve this answer






















                    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.






                    share|improve this answer












                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 24 '16 at 19:06









                    meuh

                    30.6k11753




                    30.6k11753






















                        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"





                        share|improve this answer
























                          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"





                          share|improve this answer






















                            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"





                            share|improve this answer












                            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"






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 24 '16 at 13:37









                            Gregg Leventhal

                            2,884114174




                            2,884114174




















                                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





                                share








                                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.





















                                  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





                                  share








                                  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.



















                                    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





                                    share








                                    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






                                    share








                                    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.








                                    share


                                    share






                                    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.



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        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













































































                                        Popular posts from this blog

                                        How to check contact read email or not when send email to Individual?

                                        Bahrain

                                        Postfix configuration issue with fips on centos 7; mailgun relay