1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<META NAME="generator" CONTENT="lgazmail v1.1preC">
<TITLE>The Answer Guy 33:
Conditional Execution Based on Host Availability
</TITLE>
<!-- ORIGINAL SUBJECT:
Conditional Execution Based on Host Availability
JTD SUBTITLE:
-->
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<H4>"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<H1 align="center"><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="" border="0" align="middle">
<a href="../lg_toc33.html">The Answer Guy</a>
<img src="../../gx/dennis/bbubble.gif" alt="" border="0" align="middle">
</A></H1>
<BR>
<H4 align="center">By James T. Dennis,
<a href="mailto:answerguy@ssc.com">answerguy@ssc.com</a>
<BR>Starshine Technical Services, <A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H4>
<p><hr><p>
<!--endcut ========================================================= -->
<H3><img src="../../gx/dennis/qbub.gif" alt="(?)"width="50" height="28"
align="left" border="0">Conditional Execution Based on Host Availability</H3>
<p><strong>From Vladimir Kukuruzovic on
the Linux Users Support Team mailing list
on 20 Sep 1998 </strong></p>
<!-- begin body -->
<p><strong>
Hi, regarding to your answer guy message
</strong></p>
<font color="navy"><em>
<p><strong>
Conditional Execution Based on Host Availability
</strong></p>
<p><strong>
From the L.U.S.T Mailing List on 07 Aug 1998
</strong></p>
<pre><strong>#!/path/to/perl
$ping = Ping -c 1 10.10.10.10;
exec ("program") if $ping =~ /100\% packet loss/;
</strong></pre>
<p><strong>
What's wrong with a simple:
</strong></p>
<p><strong><code>
ping -c 1 $target && $do_something $target || $complain
</code></strong></p>
<p><strong>
... where you fill $do_something and $complain with commands that you
actually want to run on success or failure of the 'ping'.
</strong></p>
<p><strong>
That's what shell "conditional execution operators" (<tt>&&</tt>
and <tt>||</tt>) are for after all.
</strong></p>
</em></font>
<p><strong>
your program does not work well with current release of net-tools and ipv6
support.
<br>you should rewrite it this way:
</strong></p>
<p><strong><code>
ping -c 1 -q $target 2> /dev/null | fgrep "1 packets received" \
<br> /dev/null && $do_something $target || $complain
</strong></p>
<blockquote><img src="../../gx/dennis/bbub.gif" height="28" width="50"
alt="(!)" border="0"
>This doesn't look right to me. My example simply
sends a ping packet and tests the return value.
It's possible that this host might not be reachable
by <EM>some</EM> ping's (ICMP's) --- that there might be
some lossage. However, I was just giving the simple
case of a "well-connected" system on the local LAN.
</blockquote>
<blockquote>
I should <EM>not</EM> have to use '<tt>grep</tt>' and parse the output
from the ping command. It should return an error level
that reflects the results.
</blockquote>
<blockquote>
If it doesn't do that in some new release --- I'll
hack it back in myself. (Ideally it might offer an
option to specify a threshold lossage percentage
--- on which it returns an error. But adding a
command line option to '<tt>ping</tt>' for this might be
"gilding the lily" --- and adding anything to it
(since it is, by nature, an SUID program) is a
unpleasant prospect.
</blockquote>
<p><strong><img src="../../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
>kind regards,
<br>Vladimir
</strong></p>
<p><strong>
p.s. the original program would say that everything is ok when
$target is in DNS, but is not reachable (no route to host)
</strong></p>
<blockquote>
By that I presume you're referring to the fragment
of perl code. Mine did not seem to do this (since
I tested it with several degenerate cases).
</blockquote>
<!-- end body -->
<!--startcut ======================================================= -->
<P> <hr> <P>
<H5 align="center"><a href="http://www.linuxgazette.com/ssc.copying.html"
>Copyright ©</a> 1998, James T. Dennis <BR>
Published in <I>Linux Gazette</I> Issue 33 October 1998</H5>
<P> <hr> <P>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<table width="98%"><tr valign="center" align="center">
<td rowspan="3"><A HREF="../lg_answer33.html"><IMG
SRC="../../gx/dennis/answernew.gif"
ALT="[ Answer Guy Index ]"></A></td>
<td><A HREF="floppy.html">floppy</a>
<td><A HREF="autocad.html">autocad</a>
<td><A HREF="scsi.html">scsi</a>
<td><A HREF="samba_pdc.html">samba_pdc</a>
<td><A HREF="virthost.html">virthost</a>
</tr><tr valign="center" align="center">
<td><A HREF="emacs_cc.html">emacs_cc</a>
<td><A HREF="ipmasq.html">ipmasq</a>
<td><A HREF="tty.html">tty</a>
<td><A HREF="shuffle.html">shuffle</a>
<td><A HREF="connect.html">connect</a>
</tr><tr valign="center" align="center">
<td><A HREF="hostavail.html">hostavail</a>
<td><A HREF="desqview.html">desqview</a>
<td><A HREF="catch22.html">catch22</a>
<td><A HREF="thanks2.html">thanks2</a>
<td><A HREF="typo.html">typo</a>
</tr></table>
<P> <hr> <P>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<A HREF="../lg_toc33.html"><IMG SRC="../../gx/indexnew.gif"
ALT="[ Table Of Contents ]"></A>
<A HREF="../../index.html"><IMG SRC="../../gx/homenew.gif"
ALT="[ Front Page ]"></A>
<A HREF="../lg_bytes33.html"><IMG SRC="../../gx/back2.gif"
ALT="[ Previous Section ]"></A>
<A HREF="../vrenios.html"><IMG SRC="../../gx/fwd.gif"
ALT="[ Next Section ]"></A>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
<!--endcut ========================================================= -->
|