[NTLUG:Discuss] Script request
Carl Haddick
sysmail at glade.net
Tue Mar 3 09:17:28 CST 2009
On Mon, Mar 02, 2009 at 06:00:25PM -0600, Fred James wrote:
> Fred
> Other responses offered may be your better choice - depending on need -
> but I offer this in case ...
>
> First ... ping on my box yields something like this (first to
> demonstrate a failure, and second to demonstrate a success) ...
> $ ping -c 3 fredless.net
> ping: unknown host fredless.net
> $ ping -c 3 www.cnc.net
> PING www.cnc.net (207.155.248.100) 56(84) bytes of data.
> 64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=1 ttl=240
> time=54.2 ms
> 64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=2 ttl=240
> time=53.7 ms
> 64 bytes from tonnant.cnc.net (207.155.248.100): icmp_seq=3 ttl=240
> time=53.7 ms
>
> --- www.cnc.net ping statistics ---
> 3 packets transmitted, 3 received, 0% packet loss, time 2000ms
> rtt min/avg/max/mdev = 53.714/53.891/54.223/0.234 ms
> $
>
> ... so I could use something like ...
>
> ping -c 3 $Name | grep "packet loss" > Tempfile.txt
> x=`wc $Tempfile.txt | awk '{ print $1 }'`
> if test $x -eq 1
> then
> PkgSent=`cat $Tempfile | awk '{ print $1 }'`
> PkgRecv=`cat $Tempfile | awk '{ print $4 }'`
> PkgLoss=`cat $Tempfile | awk '{ print $6 }'`
> else
> PkgSent=0
> PkgRecv=0
> PkgLoss=0
> fi
>
>
> Hope that helps
> Regards
> Fred James
Or, how about a bash 'if' on ping's return?
if ping www.myspiffyhost.com -nc 3 > /dev/null ; then
echo 'Oh, joyful day!'
else
echo 'Doom, despair, and misery on me...'
fi
Carl
More information about the Discuss
mailing list