[lug] Bash Scripting Ping

Ron Wright halsaves at gmail.com
Sun Nov 8 12:48:57 MST 2020


If you just trying to avoid the buffer from the pipe this will work:

stdbuf -i0 -o0 -e0 ping -O -D 10.255.255.255 2>&1 \
| while read line
do
   echo '*' $line '*'
done

A couple of notes:
  1.  I did not have to use stdbuf on Fedora 33.  The ping output lines
were not being buffered.
  2.  10.255.255.255 does not exist on my network.
  3.  You don't really need to unbuffer stdin.  So, "stdbuf -o0 -e0" should
be enough.

Ron Wright

On Sun, Nov 8, 2020 at 5:53 PM D. Stimits <stimits at comcast.net> wrote:

> I am curious about something in bash scripting which does not seem to be
> particularly easy. I wanted to script "ping -O -D address" such that each
> line gets processed by some logic if the ping fails. Redirecting ping to a
> variable does not work because it only "returns" when the ping exits (each
> line is not an exit). Even if I were to fork and exec, the forked process
> would itself have the same problem.
>
> Is there some simple/clever way to process each line of a ping in bash
> without killing off the ping itself? My goal was to send it through some
> database and statistics type processing as success/failure lines occur.
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20201108/68171465/attachment.html>


More information about the LUG mailing list