On Fri, Apr 15, 2005 at 11:17:12AM -0600, Justin Gedge wrote: > This is where you get back to the whole mess of using grep. You don't > want to check wether ping ran or not-- you want to check what the > results of ping were. Pipe the results of ping through grep-- and > filter on " 0%" or " 100%". Also-- putting the -w for timout is good > too-- otherwise ping may sit there for quite a while. I figure-- on a > good network [locally] if your ping is over 1s there are other problems > at large.
Using grep to see if ping succeeded or not is "the hard way." ping has
an exit code of 0 if there are no errors and there is a response; the
exit code is 1 or 2 otherwise. I know someone already showed the easy
way, but just to reiterate:
if ping -c 1 -w 1 -q example.com &>/dev/null; then
echo "example.com is up"
else
echo "example.com is down"
fi
--
--------------------------------+-----------------------------------
Byron Clark | http://www.byronandannie.net
[EMAIL PROTECTED] | http://bits.byronandannie.net
--------------------------------+-----------------------------------
GnuPG Fingerprint: 0365 6979 6C3E BC0C 56C0 FB7F 12B3 75DD 042B EA68
signature.asc
Description: Digital signature
.===================================. | This has been a P.L.U.G. mailing. | | Don't Fear the Penguin. | | IRC: #utah at irc.freenode.net | `==================================='
