Scripting “Screen” in Raspbian












1














I've read lot of different links such as:




  • Run script in a screen


  • https://askubuntu.com/questions/854721/creating-a-shell-script-for-use-with-screen



which all seem to say the same thing. I've tried most of the applicable options but have no clue what I'm doing wrong.



Currently I'm loading my scripts manually to not introduce any other issues possible.



Filename="startup.sh" - I create a screen on startup using an sh file containing:



#!/bin/sh
screen -dmS megadl


That works.



Filename="start.sh" - I create this file to load the detached screen and run another script.



#!/bin/sh
screen -r megadl /home/pi/mega_start.sh


It loads the screen, but nothing in mega_start.sh occurs.



Filename="mega_start.sh" - I create this file where the bulk of the code is. For testing purposes I only include echo for now.



#!/bin/sh
echo "test"


What am I doing wrong? it works up until I want start.sh to load up the mega_start.sh file.










share|improve this question





























    1














    I've read lot of different links such as:




    • Run script in a screen


    • https://askubuntu.com/questions/854721/creating-a-shell-script-for-use-with-screen



    which all seem to say the same thing. I've tried most of the applicable options but have no clue what I'm doing wrong.



    Currently I'm loading my scripts manually to not introduce any other issues possible.



    Filename="startup.sh" - I create a screen on startup using an sh file containing:



    #!/bin/sh
    screen -dmS megadl


    That works.



    Filename="start.sh" - I create this file to load the detached screen and run another script.



    #!/bin/sh
    screen -r megadl /home/pi/mega_start.sh


    It loads the screen, but nothing in mega_start.sh occurs.



    Filename="mega_start.sh" - I create this file where the bulk of the code is. For testing purposes I only include echo for now.



    #!/bin/sh
    echo "test"


    What am I doing wrong? it works up until I want start.sh to load up the mega_start.sh file.










    share|improve this question



























      1












      1








      1







      I've read lot of different links such as:




      • Run script in a screen


      • https://askubuntu.com/questions/854721/creating-a-shell-script-for-use-with-screen



      which all seem to say the same thing. I've tried most of the applicable options but have no clue what I'm doing wrong.



      Currently I'm loading my scripts manually to not introduce any other issues possible.



      Filename="startup.sh" - I create a screen on startup using an sh file containing:



      #!/bin/sh
      screen -dmS megadl


      That works.



      Filename="start.sh" - I create this file to load the detached screen and run another script.



      #!/bin/sh
      screen -r megadl /home/pi/mega_start.sh


      It loads the screen, but nothing in mega_start.sh occurs.



      Filename="mega_start.sh" - I create this file where the bulk of the code is. For testing purposes I only include echo for now.



      #!/bin/sh
      echo "test"


      What am I doing wrong? it works up until I want start.sh to load up the mega_start.sh file.










      share|improve this question















      I've read lot of different links such as:




      • Run script in a screen


      • https://askubuntu.com/questions/854721/creating-a-shell-script-for-use-with-screen



      which all seem to say the same thing. I've tried most of the applicable options but have no clue what I'm doing wrong.



      Currently I'm loading my scripts manually to not introduce any other issues possible.



      Filename="startup.sh" - I create a screen on startup using an sh file containing:



      #!/bin/sh
      screen -dmS megadl


      That works.



      Filename="start.sh" - I create this file to load the detached screen and run another script.



      #!/bin/sh
      screen -r megadl /home/pi/mega_start.sh


      It loads the screen, but nothing in mega_start.sh occurs.



      Filename="mega_start.sh" - I create this file where the bulk of the code is. For testing purposes I only include echo for now.



      #!/bin/sh
      echo "test"


      What am I doing wrong? it works up until I want start.sh to load up the mega_start.sh file.







      linux raspberry-pi gnu-screen raspbian






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 19:27









      Jeff Schaller

      38.7k1053125




      38.7k1053125










      asked Dec 16 at 18:38









      joey

      61




      61






















          1 Answer
          1






          active

          oldest

          votes


















          0














          for "what am I doing wrong" part, the answer is in the manual :)




          -r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an
          optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.




          You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:



          #!/bin/sh
          screen -S megadl -X stuff '/home/pi/mega_start.shn'
          screen -r megadl


          It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:



          $ screen -S test -X stuff 'topn'  # run top

          $ screen -r test # top displaying processes

          $ screen -S test -X stuff 'q' # kill top
          $ screen -r test # top is no longer running





          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',
            autoActivateHeartbeat: false,
            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%2f489359%2fscripting-screen-in-raspbian%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









            0














            for "what am I doing wrong" part, the answer is in the manual :)




            -r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an
            optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.




            You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:



            #!/bin/sh
            screen -S megadl -X stuff '/home/pi/mega_start.shn'
            screen -r megadl


            It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:



            $ screen -S test -X stuff 'topn'  # run top

            $ screen -r test # top displaying processes

            $ screen -S test -X stuff 'q' # kill top
            $ screen -r test # top is no longer running





            share|improve this answer


























              0














              for "what am I doing wrong" part, the answer is in the manual :)




              -r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an
              optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.




              You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:



              #!/bin/sh
              screen -S megadl -X stuff '/home/pi/mega_start.shn'
              screen -r megadl


              It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:



              $ screen -S test -X stuff 'topn'  # run top

              $ screen -r test # top displaying processes

              $ screen -S test -X stuff 'q' # kill top
              $ screen -r test # top is no longer running





              share|improve this answer
























                0












                0








                0






                for "what am I doing wrong" part, the answer is in the manual :)




                -r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an
                optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.




                You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:



                #!/bin/sh
                screen -S megadl -X stuff '/home/pi/mega_start.shn'
                screen -r megadl


                It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:



                $ screen -S test -X stuff 'topn'  # run top

                $ screen -r test # top displaying processes

                $ screen -S test -X stuff 'q' # kill top
                $ screen -r test # top is no longer running





                share|improve this answer












                for "what am I doing wrong" part, the answer is in the manual :)




                -r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an
                optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.




                You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:



                #!/bin/sh
                screen -S megadl -X stuff '/home/pi/mega_start.shn'
                screen -r megadl


                It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:



                $ screen -S test -X stuff 'topn'  # run top

                $ screen -r test # top displaying processes

                $ screen -S test -X stuff 'q' # kill top
                $ screen -r test # top is no longer running






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 17 at 0:30









                Evolter

                1614




                1614






























                    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%2f489359%2fscripting-screen-in-raspbian%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

                    Morgemoulin

                    Scott Moir

                    Souastre