[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: product exists?




On Mon, 8 Mar 1999 charles@lunargraphics.net wrote:
> I am looking for a fairly simple perl/snmp script that will ping various
> hosts, say 4 times at given intervals, and, should the ping not reply, or
> return say a string of "100% packet loss", another program would be called
> (which in my case is bip-1.2.1). 

I don't claim to be the best shell scripter in the world, nor do I claim 
to be able to get to bed at a reasonable hour, but this should at least get
you started:

add this to your crontab:

*/4 * * * *     /usr/local/bin/pinghost moocow 1> /dev/null 2>&1

replace moocow with the hostname, repeating for each host.  Then cut this
out, calling it /usr/local/bin/pinghost for my cron example:

-----------begin cut------------
#!/bin/bash

hosttoping=$1
failedpingtext='100% packet loss'

# call me with one argument - the host to ping
if [ -z "$1" ]; then
	myname=${0##/*/}
	echo "usage: $myname hostname"
	exit 1
fi

# ping once, quietly, get the last line, and grab the third chunk
hoststatus=$(ping $hosttoping -c1 -q|tail -n1|cut -d, -f3)

# get rid of the leading space
hoststatus=${hoststatus#\ }

if [ "$hoststatus" = "$failedpingtext" ]; then
	bip-1.2.1
fi
------------end cut-------------

You should be able to do a little more and make it read in a list of hosts
to ping, or something cool like that.  I need to go to bed now though. :)

--Danny


--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.