There are a number of ways to wait for the network to come up before running a script. This is one I hadn’t seen before, but I may use it in the future.
ipconfig waitall
There is also scutil -r to check the reachability of a host, which is nice.
scutil -r host.domain.com