help: infinant loop script - host ping test

need to check on some hosts and send an email if there status changes

I wanna put together a script in bash that will allow me to check the up/down state of a single host via ping

i want it to run in a continuous loop so I can just fire the script and forget about it(dont want cron to drive the script), if the host is up..then just keep pinging until its down.

At that point i want it to ping about 4 more times just ensure its not a network glitch, and if its still down send me an email. from there just keep pinging until its back online and then send me an email to let me know its up

seems easy right? not when you actually have to sit down and write (at least for me)

I've got coders block, cant seem to figure out what logic i can use to figure this out --i've been writing tons of functions and array, but am having no luck tieing them together

any help would be so very very appreciated
Tks

You could use this logic:
keep pinging as long as there is a response
if there is no response, ping four times
if still no response, send an alert, otherwise start pinging again.

an awk example, not including infinite pinging.

#!/bin/bash
awk '	function pinger(count,ip) {
		command = "ping -c "count " " ip		
		while (( command | getline res )> 0 ) {	
			if ( res ~ /0 received|100% packet loss/ ) {
				close(command)
				return 100			 
			}
		}
	close(command)
	return 0
	}	
	BEGIN { 	
	IP="x.x.x.x"	
	if ( pinger(2,IP) == 100 ) {
		print IP " Not up"
		c = 0
		while ( c < 4 ) {			
			if ( pinger(2,IP) == 100 ) {
				print IP " Not up yet" 
			}
			c=c+1
		}
	} else { print IP " up" }
}'