pend_net

Purpose: wait until a network connection is available.
Usage: pend_net [ip]

Pings ip (defaults to local gateway) to check for a network connection, repeating until success, and exits on first success. Intended for use in shell scripts: put it right before a command that accesses the network, if you have an unreliable connection.

Download pend_net

Changelog:
2022-262 initial development
2023-246 reformat/redocument a tad, dynamically get local gateway

Source code (perhaps slightly corrupted) is as follows.

if [ -n "$1" ]
then
    IP="$1"
else
    IP=`ip route | grep default | grep -o '[0-9]+.[0-9]+.[0-9]+.[0-9]+'`
fi
echo 'Waiting for working network connection ...'
while ! ping -c 1 -W 1 "$IP" >/dev/null
do
    :
done

All scripts | dkl9 home