How to autostart a program after network connection on Ubuntu?












4















How can I autostart chromium in lubuntu after a network connection?



I tried to add it ~/.config/autostart/
but chromium started before wifi connection so an error page is displayed.



I've been searched through Google but still cant find any solution.










share|improve this question





























    4















    How can I autostart chromium in lubuntu after a network connection?



    I tried to add it ~/.config/autostart/
    but chromium started before wifi connection so an error page is displayed.



    I've been searched through Google but still cant find any solution.










    share|improve this question



























      4












      4








      4


      1






      How can I autostart chromium in lubuntu after a network connection?



      I tried to add it ~/.config/autostart/
      but chromium started before wifi connection so an error page is displayed.



      I've been searched through Google but still cant find any solution.










      share|improve this question
















      How can I autostart chromium in lubuntu after a network connection?



      I tried to add it ~/.config/autostart/
      but chromium started before wifi connection so an error page is displayed.



      I've been searched through Google but still cant find any solution.







      lubuntu






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '11 at 11:04









      Diogo

      22.1k57132211




      22.1k57132211










      asked Nov 16 '11 at 10:42









      user998661user998661

      234




      234






















          3 Answers
          3






          active

          oldest

          votes


















          4














          I don't know an elegant way, but here's an approach that should work.



          Write a script that tests to see if you're online. If not, sleep for awhile and then loop back to test again. When you come online, start chrome and exit, etc.. Put that script in your autostart directory.



          In bash, the wait command is sleep. It takes an argument of the number of seconds you want to wait. It keeps your script from testing too often and using up resources.



          The trick is to figure out if you're online. One way to do that is to do something small that will fail if you're not online. Below is a hack that should be enough to get you started (if you know bash). I found the wget command trick on the web somewhere and I'm not sure exactly what it does, but it's quick and it works.



          You'll have to substitute your path for chrome.



          The ampersand at the end of the chrome line causes chrome to execute in the background so your script won't hang on that line until chrome exits. It will continue and terminate normally, leaving chrome running on its own.



          If you want to get fancy, there's a way to save the process id of the task to a file, etc., so you can easily find it and kill it later if you decide you don't want chrome to start when you come online in a particular session. But, that's a bit beyond the scope of your question. (and I don't remember how to do it ;) )



          #!/bin/bash

          function online {
          ## Test if online - prototype code
          wget -q -O /dev/null --timeout=5 http://udc.msn.com/c.gif
          return $?
          }

          until online
          do
          sleep 5
          done

          /opt/google/chrome/google-chrome &





          share|improve this answer


























          • Nice script. Works out of the box. Thanks a lot!

            – BetaRide
            Jan 2 '12 at 16:58



















          0














          I think the following should work but I am assuming you set the path to ~/.config in your ~/.bashrc



          Make sure you have the paths of your bashrc set like this



          export PATH=$PATH:$HOME/.config:/other/stuff


          instead of



          export PATH=$HOME/.config:/other/stuff:$PATH


          where $PATH is your system wide PATH settings - you are ensuring the autostart files in /etc/xdg/autostart are read before your home settings when you login.






          share|improve this answer































            0














            Working example...



            #!/bin/bash

            function online {
            ## Test if online - prototype code
            ping -c 1 google.com
            return $?
            }

            until online
            do
            sleep 5
            done

            vmware-view %u --nonInteractive &





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2fsuperuser.com%2fquestions%2f358024%2fhow-to-autostart-a-program-after-network-connection-on-ubuntu%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              I don't know an elegant way, but here's an approach that should work.



              Write a script that tests to see if you're online. If not, sleep for awhile and then loop back to test again. When you come online, start chrome and exit, etc.. Put that script in your autostart directory.



              In bash, the wait command is sleep. It takes an argument of the number of seconds you want to wait. It keeps your script from testing too often and using up resources.



              The trick is to figure out if you're online. One way to do that is to do something small that will fail if you're not online. Below is a hack that should be enough to get you started (if you know bash). I found the wget command trick on the web somewhere and I'm not sure exactly what it does, but it's quick and it works.



              You'll have to substitute your path for chrome.



              The ampersand at the end of the chrome line causes chrome to execute in the background so your script won't hang on that line until chrome exits. It will continue and terminate normally, leaving chrome running on its own.



              If you want to get fancy, there's a way to save the process id of the task to a file, etc., so you can easily find it and kill it later if you decide you don't want chrome to start when you come online in a particular session. But, that's a bit beyond the scope of your question. (and I don't remember how to do it ;) )



              #!/bin/bash

              function online {
              ## Test if online - prototype code
              wget -q -O /dev/null --timeout=5 http://udc.msn.com/c.gif
              return $?
              }

              until online
              do
              sleep 5
              done

              /opt/google/chrome/google-chrome &





              share|improve this answer


























              • Nice script. Works out of the box. Thanks a lot!

                – BetaRide
                Jan 2 '12 at 16:58
















              4














              I don't know an elegant way, but here's an approach that should work.



              Write a script that tests to see if you're online. If not, sleep for awhile and then loop back to test again. When you come online, start chrome and exit, etc.. Put that script in your autostart directory.



              In bash, the wait command is sleep. It takes an argument of the number of seconds you want to wait. It keeps your script from testing too often and using up resources.



              The trick is to figure out if you're online. One way to do that is to do something small that will fail if you're not online. Below is a hack that should be enough to get you started (if you know bash). I found the wget command trick on the web somewhere and I'm not sure exactly what it does, but it's quick and it works.



              You'll have to substitute your path for chrome.



              The ampersand at the end of the chrome line causes chrome to execute in the background so your script won't hang on that line until chrome exits. It will continue and terminate normally, leaving chrome running on its own.



              If you want to get fancy, there's a way to save the process id of the task to a file, etc., so you can easily find it and kill it later if you decide you don't want chrome to start when you come online in a particular session. But, that's a bit beyond the scope of your question. (and I don't remember how to do it ;) )



              #!/bin/bash

              function online {
              ## Test if online - prototype code
              wget -q -O /dev/null --timeout=5 http://udc.msn.com/c.gif
              return $?
              }

              until online
              do
              sleep 5
              done

              /opt/google/chrome/google-chrome &





              share|improve this answer


























              • Nice script. Works out of the box. Thanks a lot!

                – BetaRide
                Jan 2 '12 at 16:58














              4












              4








              4







              I don't know an elegant way, but here's an approach that should work.



              Write a script that tests to see if you're online. If not, sleep for awhile and then loop back to test again. When you come online, start chrome and exit, etc.. Put that script in your autostart directory.



              In bash, the wait command is sleep. It takes an argument of the number of seconds you want to wait. It keeps your script from testing too often and using up resources.



              The trick is to figure out if you're online. One way to do that is to do something small that will fail if you're not online. Below is a hack that should be enough to get you started (if you know bash). I found the wget command trick on the web somewhere and I'm not sure exactly what it does, but it's quick and it works.



              You'll have to substitute your path for chrome.



              The ampersand at the end of the chrome line causes chrome to execute in the background so your script won't hang on that line until chrome exits. It will continue and terminate normally, leaving chrome running on its own.



              If you want to get fancy, there's a way to save the process id of the task to a file, etc., so you can easily find it and kill it later if you decide you don't want chrome to start when you come online in a particular session. But, that's a bit beyond the scope of your question. (and I don't remember how to do it ;) )



              #!/bin/bash

              function online {
              ## Test if online - prototype code
              wget -q -O /dev/null --timeout=5 http://udc.msn.com/c.gif
              return $?
              }

              until online
              do
              sleep 5
              done

              /opt/google/chrome/google-chrome &





              share|improve this answer















              I don't know an elegant way, but here's an approach that should work.



              Write a script that tests to see if you're online. If not, sleep for awhile and then loop back to test again. When you come online, start chrome and exit, etc.. Put that script in your autostart directory.



              In bash, the wait command is sleep. It takes an argument of the number of seconds you want to wait. It keeps your script from testing too often and using up resources.



              The trick is to figure out if you're online. One way to do that is to do something small that will fail if you're not online. Below is a hack that should be enough to get you started (if you know bash). I found the wget command trick on the web somewhere and I'm not sure exactly what it does, but it's quick and it works.



              You'll have to substitute your path for chrome.



              The ampersand at the end of the chrome line causes chrome to execute in the background so your script won't hang on that line until chrome exits. It will continue and terminate normally, leaving chrome running on its own.



              If you want to get fancy, there's a way to save the process id of the task to a file, etc., so you can easily find it and kill it later if you decide you don't want chrome to start when you come online in a particular session. But, that's a bit beyond the scope of your question. (and I don't remember how to do it ;) )



              #!/bin/bash

              function online {
              ## Test if online - prototype code
              wget -q -O /dev/null --timeout=5 http://udc.msn.com/c.gif
              return $?
              }

              until online
              do
              sleep 5
              done

              /opt/google/chrome/google-chrome &






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 22 '11 at 0:44

























              answered Nov 22 '11 at 0:37









              JoeJoe

              503613




              503613













              • Nice script. Works out of the box. Thanks a lot!

                – BetaRide
                Jan 2 '12 at 16:58



















              • Nice script. Works out of the box. Thanks a lot!

                – BetaRide
                Jan 2 '12 at 16:58

















              Nice script. Works out of the box. Thanks a lot!

              – BetaRide
              Jan 2 '12 at 16:58





              Nice script. Works out of the box. Thanks a lot!

              – BetaRide
              Jan 2 '12 at 16:58













              0














              I think the following should work but I am assuming you set the path to ~/.config in your ~/.bashrc



              Make sure you have the paths of your bashrc set like this



              export PATH=$PATH:$HOME/.config:/other/stuff


              instead of



              export PATH=$HOME/.config:/other/stuff:$PATH


              where $PATH is your system wide PATH settings - you are ensuring the autostart files in /etc/xdg/autostart are read before your home settings when you login.






              share|improve this answer




























                0














                I think the following should work but I am assuming you set the path to ~/.config in your ~/.bashrc



                Make sure you have the paths of your bashrc set like this



                export PATH=$PATH:$HOME/.config:/other/stuff


                instead of



                export PATH=$HOME/.config:/other/stuff:$PATH


                where $PATH is your system wide PATH settings - you are ensuring the autostart files in /etc/xdg/autostart are read before your home settings when you login.






                share|improve this answer


























                  0












                  0








                  0







                  I think the following should work but I am assuming you set the path to ~/.config in your ~/.bashrc



                  Make sure you have the paths of your bashrc set like this



                  export PATH=$PATH:$HOME/.config:/other/stuff


                  instead of



                  export PATH=$HOME/.config:/other/stuff:$PATH


                  where $PATH is your system wide PATH settings - you are ensuring the autostart files in /etc/xdg/autostart are read before your home settings when you login.






                  share|improve this answer













                  I think the following should work but I am assuming you set the path to ~/.config in your ~/.bashrc



                  Make sure you have the paths of your bashrc set like this



                  export PATH=$PATH:$HOME/.config:/other/stuff


                  instead of



                  export PATH=$HOME/.config:/other/stuff:$PATH


                  where $PATH is your system wide PATH settings - you are ensuring the autostart files in /etc/xdg/autostart are read before your home settings when you login.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 30 '13 at 17:00









                  MagpieMagpie

                  1211110




                  1211110























                      0














                      Working example...



                      #!/bin/bash

                      function online {
                      ## Test if online - prototype code
                      ping -c 1 google.com
                      return $?
                      }

                      until online
                      do
                      sleep 5
                      done

                      vmware-view %u --nonInteractive &





                      share|improve this answer




























                        0














                        Working example...



                        #!/bin/bash

                        function online {
                        ## Test if online - prototype code
                        ping -c 1 google.com
                        return $?
                        }

                        until online
                        do
                        sleep 5
                        done

                        vmware-view %u --nonInteractive &





                        share|improve this answer


























                          0












                          0








                          0







                          Working example...



                          #!/bin/bash

                          function online {
                          ## Test if online - prototype code
                          ping -c 1 google.com
                          return $?
                          }

                          until online
                          do
                          sleep 5
                          done

                          vmware-view %u --nonInteractive &





                          share|improve this answer













                          Working example...



                          #!/bin/bash

                          function online {
                          ## Test if online - prototype code
                          ping -c 1 google.com
                          return $?
                          }

                          until online
                          do
                          sleep 5
                          done

                          vmware-view %u --nonInteractive &






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 5 at 19:56









                          user994545user994545

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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%2fsuperuser.com%2fquestions%2f358024%2fhow-to-autostart-a-program-after-network-connection-on-ubuntu%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 make a Squid Proxy server?

                              Is this a new Fibonacci Identity?

                              19世紀