How can I launch Firefox when there is internet connectivity?

If you put Thom's (@tkn) oneliner in an rc script, it will run at boot and loop until it gets the required connection.

But ... that may not be successful unless you also add a condition to verify that your login Display session is actually open and that the window has a desktop to open into.



I put together the script you can

  • save as (new) or
  • add to (existing
/etc/rc.local

Script:

#!/bin/sh

networkConnected()
{
	# CONDITION:	Return Code = 0
	ping -c 1 google.com >/dev/null 2>&1
	echo $?
}

while [ $(networkConnected) != "0" ]
do
	sleep 10
done


displayOpen()
{
	# CONDITION:	/usr/lib/xorg/Xorg -dpms -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
	ps -ef | grep '[-]core :0'
}

while [ -z "$(displayOpen)" ]
do
	sleep 10 
done

#echo "clear to start Firefox"
firefox

That will run at boot time and continue until you desktop is available. Just make sure it is executable.

:slight_smile:

2 Likes