Starting a script at boot time and having it wait for the network to come up would be a weird and complicated way of doing what you want, which is to run something when the network comes up.
If you want to do something when the network comes up, then add it to the network startup scripts, not to the system startup scripts. Systemd and Upstart unify these, but Debian wheezy uses a traditional init system, which only manages startup (and runlevel changes).
Under Debian and derivatives, you can put a script to run when an interface comes up in
If you need to monitor Internet connectivity as opposed to network connectivity, you need to do several things:
- Pick a definition of network connectivity. The Internet is not centralized; you can only check whether a particular host is responding to a particular request. This can be affected by firewalls along the way.
- Decide how long the network can be down before you react. This depends on what you want to achieve. If you pick a too short interval, a simple dropped packet will make you wrongly decide that the network is down. If you pick a too long interval, you won't detect failed connectivity fast.
There's no magic way to accomplish this. The most obvious way is to contact the server chosen for (1.), in a loop which sleeps for a time chosen for (2.) between contact attempts. This is the only way to detect when connectivity starts. There are other ways to observe loss of connectivity, such as opening a TCP connection and sending packets from time to time on that opened connection.
There are three possible approaches:
- Put a crontab that tests connectivity at regular intervals, saves the state in a file and reacts when the state change.
- Have a shell (or other) script running forever that loops forever around the connectivity test.
- Use a more advanced monitoring tool.