btw, if I need to check if the network is up in a script, I usually do
ping -q -c1 -w4 some.remote.host >/dev/null 2>&1 && command-to-run-if-remote-host-reachable
It the advantage that it checks directly connection to the host
you wish to connect to, so it also won't run the command if your network
is up, but the remote host is inaccessible...
If your server doesn't respond to pings, just use some other server
(eg google's public dns 8.8.8.8)