bash script to start another script in a tmux session

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











up vote
1
down vote

favorite
1












I have a bash script that continuously outputs some information when run. I need to



  1. Automatically run this when my system boots.

  2. Monitor this output and control it every once in a while remotely, using ssh.

For this purpose, I would like to use tmux. So how do I approach this? For simplicity, let's say my shell script is this:



filename: start.bash



#!/bin/bash
# just an example for simplicity
watch date


I need another script that runs this in tmux and be able to attach to this when I need, later. I am struggling at the part where I need to create a new tmux session with a name and make it run another shell script. Once I have this working, I can put this in another shell script and take care of the rest of the stuff. That is easy, I think. Can someone give me an example for this specific step please?







share|improve this question
























    up vote
    1
    down vote

    favorite
    1












    I have a bash script that continuously outputs some information when run. I need to



    1. Automatically run this when my system boots.

    2. Monitor this output and control it every once in a while remotely, using ssh.

    For this purpose, I would like to use tmux. So how do I approach this? For simplicity, let's say my shell script is this:



    filename: start.bash



    #!/bin/bash
    # just an example for simplicity
    watch date


    I need another script that runs this in tmux and be able to attach to this when I need, later. I am struggling at the part where I need to create a new tmux session with a name and make it run another shell script. Once I have this working, I can put this in another shell script and take care of the rest of the stuff. That is easy, I think. Can someone give me an example for this specific step please?







    share|improve this question






















      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I have a bash script that continuously outputs some information when run. I need to



      1. Automatically run this when my system boots.

      2. Monitor this output and control it every once in a while remotely, using ssh.

      For this purpose, I would like to use tmux. So how do I approach this? For simplicity, let's say my shell script is this:



      filename: start.bash



      #!/bin/bash
      # just an example for simplicity
      watch date


      I need another script that runs this in tmux and be able to attach to this when I need, later. I am struggling at the part where I need to create a new tmux session with a name and make it run another shell script. Once I have this working, I can put this in another shell script and take care of the rest of the stuff. That is easy, I think. Can someone give me an example for this specific step please?







      share|improve this question












      I have a bash script that continuously outputs some information when run. I need to



      1. Automatically run this when my system boots.

      2. Monitor this output and control it every once in a while remotely, using ssh.

      For this purpose, I would like to use tmux. So how do I approach this? For simplicity, let's say my shell script is this:



      filename: start.bash



      #!/bin/bash
      # just an example for simplicity
      watch date


      I need another script that runs this in tmux and be able to attach to this when I need, later. I am struggling at the part where I need to create a new tmux session with a name and make it run another shell script. Once I have this working, I can put this in another shell script and take care of the rest of the stuff. That is easy, I think. Can someone give me an example for this specific step please?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 15 '17 at 21:02









      code4kix

      1155




      1155




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          You can do this many ways.



          You can do it after you've created the session either with send-keys:



          tmux new -s "remote" -d
          tmux send-keys -t "remote" "start.bash" C-m
          tmux attach -t "remote" -d


          Or through the shell:



          tmux new -s "remote" -d "/bin/bash"
          tmux run-shell -t "remote:0" "start.bash"
          tmux attach -t "remote" -d





          share|improve this answer



























            up vote
            0
            down vote













            Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run



            tmux attach


            to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local






            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: 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%2f411141%2fbash-script-to-start-another-script-in-a-tmux-session%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote



              accepted










              You can do this many ways.



              You can do it after you've created the session either with send-keys:



              tmux new -s "remote" -d
              tmux send-keys -t "remote" "start.bash" C-m
              tmux attach -t "remote" -d


              Or through the shell:



              tmux new -s "remote" -d "/bin/bash"
              tmux run-shell -t "remote:0" "start.bash"
              tmux attach -t "remote" -d





              share|improve this answer
























                up vote
                2
                down vote



                accepted










                You can do this many ways.



                You can do it after you've created the session either with send-keys:



                tmux new -s "remote" -d
                tmux send-keys -t "remote" "start.bash" C-m
                tmux attach -t "remote" -d


                Or through the shell:



                tmux new -s "remote" -d "/bin/bash"
                tmux run-shell -t "remote:0" "start.bash"
                tmux attach -t "remote" -d





                share|improve this answer






















                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  You can do this many ways.



                  You can do it after you've created the session either with send-keys:



                  tmux new -s "remote" -d
                  tmux send-keys -t "remote" "start.bash" C-m
                  tmux attach -t "remote" -d


                  Or through the shell:



                  tmux new -s "remote" -d "/bin/bash"
                  tmux run-shell -t "remote:0" "start.bash"
                  tmux attach -t "remote" -d





                  share|improve this answer












                  You can do this many ways.



                  You can do it after you've created the session either with send-keys:



                  tmux new -s "remote" -d
                  tmux send-keys -t "remote" "start.bash" C-m
                  tmux attach -t "remote" -d


                  Or through the shell:



                  tmux new -s "remote" -d "/bin/bash"
                  tmux run-shell -t "remote:0" "start.bash"
                  tmux attach -t "remote" -d






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 15 '17 at 23:38









                  jdwolf

                  2,392116




                  2,392116






















                      up vote
                      0
                      down vote













                      Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run



                      tmux attach


                      to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run



                        tmux attach


                        to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run



                          tmux attach


                          to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local






                          share|improve this answer












                          Start a tmux session on the server and do not close it. It will keep running on the server. From your client computer you will be able to ssh in and run



                          tmux attach


                          to reconnect to whatever you had running in the tmux session. To start it at boot time if you reboot the server start tmux from a shell script that runs from /etc/rc.local







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 17 '17 at 1:19









                          tluafed

                          111




                          111






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f411141%2fbash-script-to-start-another-script-in-a-tmux-session%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)