get pppd exit code - how?

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'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.



99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.



As in production box will work remotely with no physical access to it so I have to manage it somehow.



My idea is to run at system start, some kind of script in separate thread see below pseudocode:



while(true)
wait_for_modem_device_to_appear
start_pppd # may_be limiting retries not to default 10, but to, say, 3
wait_for_pppd_to_finish
if(exitcode_is_one_of(6,7,8,10,15,16))
reset_usb_port_programmatically #I have tools for that
else
break




  • How can I get pppd exit code?

  • Should I use another approach (which)?






share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.



    99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.



    As in production box will work remotely with no physical access to it so I have to manage it somehow.



    My idea is to run at system start, some kind of script in separate thread see below pseudocode:



    while(true)
    wait_for_modem_device_to_appear
    start_pppd # may_be limiting retries not to default 10, but to, say, 3
    wait_for_pppd_to_finish
    if(exitcode_is_one_of(6,7,8,10,15,16))
    reset_usb_port_programmatically #I have tools for that
    else
    break




    • How can I get pppd exit code?

    • Should I use another approach (which)?






    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.



      99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.



      As in production box will work remotely with no physical access to it so I have to manage it somehow.



      My idea is to run at system start, some kind of script in separate thread see below pseudocode:



      while(true)
      wait_for_modem_device_to_appear
      start_pppd # may_be limiting retries not to default 10, but to, say, 3
      wait_for_pppd_to_finish
      if(exitcode_is_one_of(6,7,8,10,15,16))
      reset_usb_port_programmatically #I have tools for that
      else
      break




      • How can I get pppd exit code?

      • Should I use another approach (which)?






      share|improve this question














      I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.



      99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.



      As in production box will work remotely with no physical access to it so I have to manage it somehow.



      My idea is to run at system start, some kind of script in separate thread see below pseudocode:



      while(true)
      wait_for_modem_device_to_appear
      start_pppd # may_be limiting retries not to default 10, but to, say, 3
      wait_for_pppd_to_finish
      if(exitcode_is_one_of(6,7,8,10,15,16))
      reset_usb_port_programmatically #I have tools for that
      else
      break




      • How can I get pppd exit code?

      • Should I use another approach (which)?








      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 at 14:38

























      asked Mar 6 at 14:09









      DmitryD

      63




      63




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          After calling 'pppd' you need get value of variable '$?'.



          $? - get exit code of last program.



          For background processes '$!' may be useful with some cover.



          $! - get PID of last background process that was executed.



          Example scenario:



          run_background_process &
          pid_of_background_process=$!
          wait $pid_of_background_process
          echo "Result code of background process: "$?





          share|improve this answer






















          • Yury, ppd is running on background so you will get 0 always
            – DmitryD
            Mar 6 at 14:18










          • @DmitryD, I've supplemented answer.
            – Yurij Goncharuk
            Mar 6 at 14:39











          • Solution you proposed doesn't work even with supplement, but thanks for your try!
            – DmitryD
            Mar 14 at 17:05


















          up vote
          0
          down vote



          accepted










          Bingo!



          Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:



          pppd call my_provider nodetach maxfail 3
          echo $?





          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%2f428518%2fget-pppd-exit-code-how%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
            0
            down vote













            After calling 'pppd' you need get value of variable '$?'.



            $? - get exit code of last program.



            For background processes '$!' may be useful with some cover.



            $! - get PID of last background process that was executed.



            Example scenario:



            run_background_process &
            pid_of_background_process=$!
            wait $pid_of_background_process
            echo "Result code of background process: "$?





            share|improve this answer






















            • Yury, ppd is running on background so you will get 0 always
              – DmitryD
              Mar 6 at 14:18










            • @DmitryD, I've supplemented answer.
              – Yurij Goncharuk
              Mar 6 at 14:39











            • Solution you proposed doesn't work even with supplement, but thanks for your try!
              – DmitryD
              Mar 14 at 17:05















            up vote
            0
            down vote













            After calling 'pppd' you need get value of variable '$?'.



            $? - get exit code of last program.



            For background processes '$!' may be useful with some cover.



            $! - get PID of last background process that was executed.



            Example scenario:



            run_background_process &
            pid_of_background_process=$!
            wait $pid_of_background_process
            echo "Result code of background process: "$?





            share|improve this answer






















            • Yury, ppd is running on background so you will get 0 always
              – DmitryD
              Mar 6 at 14:18










            • @DmitryD, I've supplemented answer.
              – Yurij Goncharuk
              Mar 6 at 14:39











            • Solution you proposed doesn't work even with supplement, but thanks for your try!
              – DmitryD
              Mar 14 at 17:05













            up vote
            0
            down vote










            up vote
            0
            down vote









            After calling 'pppd' you need get value of variable '$?'.



            $? - get exit code of last program.



            For background processes '$!' may be useful with some cover.



            $! - get PID of last background process that was executed.



            Example scenario:



            run_background_process &
            pid_of_background_process=$!
            wait $pid_of_background_process
            echo "Result code of background process: "$?





            share|improve this answer














            After calling 'pppd' you need get value of variable '$?'.



            $? - get exit code of last program.



            For background processes '$!' may be useful with some cover.



            $! - get PID of last background process that was executed.



            Example scenario:



            run_background_process &
            pid_of_background_process=$!
            wait $pid_of_background_process
            echo "Result code of background process: "$?






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 6 at 14:38

























            answered Mar 6 at 14:13









            Yurij Goncharuk

            2,2582521




            2,2582521











            • Yury, ppd is running on background so you will get 0 always
              – DmitryD
              Mar 6 at 14:18










            • @DmitryD, I've supplemented answer.
              – Yurij Goncharuk
              Mar 6 at 14:39











            • Solution you proposed doesn't work even with supplement, but thanks for your try!
              – DmitryD
              Mar 14 at 17:05

















            • Yury, ppd is running on background so you will get 0 always
              – DmitryD
              Mar 6 at 14:18










            • @DmitryD, I've supplemented answer.
              – Yurij Goncharuk
              Mar 6 at 14:39











            • Solution you proposed doesn't work even with supplement, but thanks for your try!
              – DmitryD
              Mar 14 at 17:05
















            Yury, ppd is running on background so you will get 0 always
            – DmitryD
            Mar 6 at 14:18




            Yury, ppd is running on background so you will get 0 always
            – DmitryD
            Mar 6 at 14:18












            @DmitryD, I've supplemented answer.
            – Yurij Goncharuk
            Mar 6 at 14:39





            @DmitryD, I've supplemented answer.
            – Yurij Goncharuk
            Mar 6 at 14:39













            Solution you proposed doesn't work even with supplement, but thanks for your try!
            – DmitryD
            Mar 14 at 17:05





            Solution you proposed doesn't work even with supplement, but thanks for your try!
            – DmitryD
            Mar 14 at 17:05













            up vote
            0
            down vote



            accepted










            Bingo!



            Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:



            pppd call my_provider nodetach maxfail 3
            echo $?





            share|improve this answer
























              up vote
              0
              down vote



              accepted










              Bingo!



              Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:



              pppd call my_provider nodetach maxfail 3
              echo $?





              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Bingo!



                Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:



                pppd call my_provider nodetach maxfail 3
                echo $?





                share|improve this answer












                Bingo!



                Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:



                pppd call my_provider nodetach maxfail 3
                echo $?






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 14 at 17:05









                DmitryD

                63




                63






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428518%2fget-pppd-exit-code-how%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