tmux send-keys confirm ssh tunnel is closed (after sending multiple commands to the remote host) before proceeding

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











up vote
0
down vote

favorite












there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.



LocalCommand doesn't do this.



here's the question:



After:

1. opening a new tmux session

2. using send-keys to establish an ssh tunnel

3. sending multiple commands to the remote host using send-keys

4. closing the ssh tunnel using send-keys



How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?










share|improve this question



























    up vote
    0
    down vote

    favorite












    there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.



    LocalCommand doesn't do this.



    here's the question:



    After:

    1. opening a new tmux session

    2. using send-keys to establish an ssh tunnel

    3. sending multiple commands to the remote host using send-keys

    4. closing the ssh tunnel using send-keys



    How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.



      LocalCommand doesn't do this.



      here's the question:



      After:

      1. opening a new tmux session

      2. using send-keys to establish an ssh tunnel

      3. sending multiple commands to the remote host using send-keys

      4. closing the ssh tunnel using send-keys



      How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?










      share|improve this question















      there is an answer here about tmux using wait-for and LocalCommand to wait until the SSH connection is established before continuing, but I needed a way to have tmux wait for the ssh session to be closed (after using send-keys to the remote host in multiple commands) before continuing.



      LocalCommand doesn't do this.



      here's the question:



      After:

      1. opening a new tmux session

      2. using send-keys to establish an ssh tunnel

      3. sending multiple commands to the remote host using send-keys

      4. closing the ssh tunnel using send-keys



      How can I ensure bash waits until the terminal is ready to receive input before executing the next tmux send-keys command?







      shell-script ssh tmux wait






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 at 15:18

























      asked Nov 28 at 15:06









      p4ndepravity

      12




      12




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          How I ended up solving this:



          rm ~/sesh.lock 2> /dev/null # in case of previous failure
          tmux new-session -d -s sesh
          tmux send-keys -t sesh "ssh prod-srv-1" Enter
          tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
          tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
          tmux send-keys -t sesh exit Enter

          while [ ! -e ~/sesh.lock ]
          do
          tmux send-keys -t sesh "touch ~/sesh.lock" Enter
          sleep 0.1
          done
          tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter

          tmux kill-session -t sesh





          share|improve this answer




















            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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            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%2f484687%2ftmux-send-keys-confirm-ssh-tunnel-is-closed-after-sending-multiple-commands-to%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            How I ended up solving this:



            rm ~/sesh.lock 2> /dev/null # in case of previous failure
            tmux new-session -d -s sesh
            tmux send-keys -t sesh "ssh prod-srv-1" Enter
            tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
            tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
            tmux send-keys -t sesh exit Enter

            while [ ! -e ~/sesh.lock ]
            do
            tmux send-keys -t sesh "touch ~/sesh.lock" Enter
            sleep 0.1
            done
            tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter

            tmux kill-session -t sesh





            share|improve this answer
























              up vote
              0
              down vote













              How I ended up solving this:



              rm ~/sesh.lock 2> /dev/null # in case of previous failure
              tmux new-session -d -s sesh
              tmux send-keys -t sesh "ssh prod-srv-1" Enter
              tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
              tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
              tmux send-keys -t sesh exit Enter

              while [ ! -e ~/sesh.lock ]
              do
              tmux send-keys -t sesh "touch ~/sesh.lock" Enter
              sleep 0.1
              done
              tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter

              tmux kill-session -t sesh





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                How I ended up solving this:



                rm ~/sesh.lock 2> /dev/null # in case of previous failure
                tmux new-session -d -s sesh
                tmux send-keys -t sesh "ssh prod-srv-1" Enter
                tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
                tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
                tmux send-keys -t sesh exit Enter

                while [ ! -e ~/sesh.lock ]
                do
                tmux send-keys -t sesh "touch ~/sesh.lock" Enter
                sleep 0.1
                done
                tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter

                tmux kill-session -t sesh





                share|improve this answer












                How I ended up solving this:



                rm ~/sesh.lock 2> /dev/null # in case of previous failure
                tmux new-session -d -s sesh
                tmux send-keys -t sesh "ssh prod-srv-1" Enter
                tmux send-keys -t sesh "cd /srv/www/api/bin" Enter
                tmux send-keys -t sesh "echo api stop > ~/api_log.txt" Enter
                tmux send-keys -t sesh exit Enter

                while [ ! -e ~/sesh.lock ]
                do
                tmux send-keys -t sesh "touch ~/sesh.lock" Enter
                sleep 0.1
                done
                tmux send-keys -t sesh "rm ~/sesh.lock 2> /dev/null" Enter

                tmux kill-session -t sesh






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 28 at 15:16









                p4ndepravity

                12




                12



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484687%2ftmux-send-keys-confirm-ssh-tunnel-is-closed-after-sending-multiple-commands-to%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

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

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?