For some highly customised Linux distros I have deployed, often minimal kernels with install scripts for system maintenance, I find checking and more importantly, waiting, for an Internet connection, essential.
This script is useful in situations such as waiting for network availability at startup, where some daemons such as Network-Manager are not fully initialised by the time any scripts in rc.local may be firing.
This script takes care of that. You may want to change the target of the Ping command to an internal server, this would be best if it is the one you are trying to contact. If no response to the ping is received, the script will wait a second and retry a ping. If the connection is available, the script will then state so and wait two seconds.
Two important notes:
- Ping an FQDN rather than an IP – this verifies that DNS resolution is functional as well as ICMP responses, and verifies that network connectivity is indeed successful.
- Always “sleep 2″ after the network connection is registered as initalised. This is the perfect amount of time between the scripts detection and the NICs initialisation of full networking functionality, otherwise, you may get errors with wget or further ping commands.
Grab from SVN here