[Gloucs] What's wrong with this code?

Andy Teague andy.teague at ukonline.co.uk
Tue Jul 31 20:14:05 BST 2007


Glyn Davies wrote:
> No prizes for getting the answer right as I've found it and feel free 
> to spot the problem immediately and make me look a fool.
>
> What's wrong with this line of code. Okay, other than it being a 
> rubbish way of testing that your gateway is available?
>
> if [ "$(ping -c 1 192.168.1.200 | grep '1 received')" != "" ]
>
> P.S. I expect I'll learn of other ways in which it is 'wrong' and not 
> just mine.
>

well - it sort of worked for me, (as a code fragment - see below) with 
some caveats:
a) it assumes ping is on your path, may not be true if running in cron, 
same for grep
b) it assumes that ping success means gateway is funtional - OS could 
still be unavailible
c) it tells you nothing about the link out of the gateway
d) it assumes your ping wont hang indefinately (ie it does time out)

What did YOU think was wrong with it??
(surely not just the ;  ?)


#!/bin/sh
if [ "$(ping -c 1 192.168.99.99 | grep '1 received')" != "" ];
then
        echo "up"
else
        echo "down"
fi








More information about the gloucs mailing list