[lug] Bash Scripting Ping
D. Stimits
stimits at comcast.net
Sun Nov 8 13:55:06 MST 2020
> On 11/08/2020 12:48 PM Ron Wright <halsaves at gmail.com> wrote:
>
>
> 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
>
So far this one is looking like it works. I'll have to spend some time trying different edits, but think the non-buffered output piped to the while of read line is the answer. I never really thought of piping to while before, nor have I used stdbuf before, but it is something new and shiny!
> 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 mailto: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:http://irc.hackingsociety.org port=6667 channel=#hackingsociety
> >
> > > _______________________________________________
> 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/e91e786a/attachment.html>
More information about the LUG
mailing list