Xælias
Xælias

Reputation: 868

Tail multiple remote files and pipe the result

I'm looking for a way to pipe multiple log files on multiple remote servers, and then pipe the result to another program.

Right now I'm using multitail, but it does not exactly do what I need, or maybe I'm doing something wrong!

I would like to be able to send the merge of all log files, to another program. For example jq. Right now if I do:

multitail --mergeall -l 'ssh server1 "tail -f /path/to/log"' -l 'ssh server2 "tail -f /path/to/log"' -l 'ssh server3 "tail -f /path/to/log"' | jq .

for instance, I get this:

parse error: Invalid numeric literal at line 1, column 2

But more generally, I would like to give the output of this to another program I use to parse and display logs :-)

Thanks everybody!

Upvotes: 0

Views: 1111

Answers (1)

Rob
Rob

Reputation: 755

One way to accomplish this feat would be to pipe all your outputs together into a named pipe and then deal with the output from that named pipe.

First, create your named pipe: $ mknod MYFIFO p

For each location you want to consolidate lines from, $ tail -f logfile > MYFIFO (note, the tail -f can be run through an ssh session).

Then have another process take the data out of the named pipe and handle it appropriately. An ugly solution could be:

$ tail -f MYFIFO | jq

Season to taste.

Upvotes: 1

Related Questions