[lug] Bash Scripting Ping

Ron Wright halsaves at gmail.com
Sun Nov 8 13:14:30 MST 2020


Yeah.  Here is a better example, as 'ping' doesn't buffer, but both 'cut'
and 'grep' do:

#  Buffered output
ping -O -D 10.255.255.255 \
| grep 'no answer yet' \
| while read line
do
  echo '*' $line '*'
done

# Non-buffered output
ping -O -D 10.255.255.255 \
| stdbuf -o0 grep 'no answer yet' \
| while read line
do
  echo '*' $line '*'
done


On Sun, Nov 8, 2020 at 7:54 PM Jed S. Baer <blug at jbaer.cotse.net> wrote:

> On Sun, 8 Nov 2020 19:48:57 +0000
> Ron Wright wrote:
>
> > If you just trying to avoid the buffer from the pipe this will work:
>
> I didn't notice any timing quirks when simply doing ping -c N to get more
> lines of output. I added in -i 5 to see whether the script output stalled,
> and then clumped together, but it ticked along at a 5 second interval,
> without having to do anything special.
>
> --
> All operating systems suck, but Linux just sucks less
>  - Linus Torvalds
> _______________________________________________
> 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/720c0dfc/attachment.html>


More information about the LUG mailing list