Read through the manpage for wget. There are options you may want such as -c (continue partially downloaded file) --tries (will keep trying to make a connection). Using these and other options, the wget command by itself may solve most of the problems.
I'm not certain of the return values for wget. If a return value indicates no network connection, then you could act on it with `ifup' or something similar inside a while loop. Wget can also produce a log, which you could also parse to determine more problems than indicated by a return value.
In a script you might use the return value of a command to control whether a while loop continues or an if command branches.
You can also test $? immediately after the command or assign $? to a status flag immediately after a command runs.
if grep exbit /etc/services; then echo "found it"; fi
if grep exbim /etc/services; then echo "found"; else echo "not found"
You can also use the case command.
Code:
grep exbim /etc/services
status=$?
case $status in 0) echo "found" ;;
1) echo "not found" ;;
2) echo "file doesn't exist" ;;
esac
If you have a single if - then - else structure look at || and &&
command1 && command2 || command3
If command1 is successful, execute command2 else execute command3.