If you want to do it where it keeps checking, and does something different depending on the state, you are right, a while loop is probably a better option. There are a ton of ways to accomplish this, here is a simple example I came up with that would certainly need modification, but could be a start.
PING="/bin/ping -q -c1"
while [ true ]
if [ $? -ne 0 ]; then
echo "Link is down"
This is an infinite loop, because
true always equals true. So this will keep running until you break out of it. Each time through the loop it will ping whatever host is configured by the variable 1 time, then it checks the return value
$? of the last command. If that is not 0, then the ping failed, and the assumption is that the link is down. Then it pauses for some period of time (in this case 3 seconds) and tries again because true is still true.