Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 4 down vote accepted

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
    
it works!! thanks! –  user998661 Nov 23 '11 at 9:38
    
Nice script. Works out of the box. Thanks a lot! –  BetaRide Jan 2 '12 at 16:58

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.