[lug] Bash Scripting Ping

Jed S. Baer blug at jbaer.cotse.net
Sun Nov 8 12:01:48 MST 2020


On Sun, 8 Nov 2020 11:50:18 -0700 (MST)
D. Stimits wrote:

> A single ping is a single line of text, followed by termination of the
> process providing the text. I am interested in parsing sections of a
> continuous, never ending string of text whenever a newline is found. Each
> newline providing a "token" to process, but the text stream never ending.

A "single" ping, yes. But the output of a ping command can approximate what
you describe. I used "-c 3" just to get several lines, but substitute some
arbitrary really big number for the count, in ping (just as an example) and
you'll get what you described (until the counting is complete - then
throwest thou thy Holy Hand Grenade at thy foe).

Piping the output to bash's read command will read each line, until EOF or
an error occurs. So, your arbitrary never-ending stream won't have EOF, so
the bash read loop will just keep executing.

Well, that's how I understand it.

There could be more complicated solutions, using named pipes, which you
could set up in bash as well. But I think you'd still use the bash read
command to get the output into variables.
-- 
All operating systems suck, but Linux just sucks less
 - Linus Torvalds


More information about the LUG mailing list