Article 4SEJN How to grep string from log files on multiple servers into one single file on server1?

How to grep string from log files on multiple servers into one single file on server1?

by
JugaruGabi
from LinuxQuestions.org on (#4SEJN)
Hello guys,

A bit of help on a matter in which I was not able to find any kind of hints anywhere and I would like to know if you guys have an idea:

So, I am having the following 32 servers:
server1
server2
server3
.
.
server32

The list is stored in a file named hosts.

In each of this servers, I have 8 logfiles similar to the following:
/path/to/file/logfile.log
/path/to/file/logfile.1.log
/path/to/file/logfile.2.log
/path/to/file/logfile.3.log

Now, the dirty part:
I need to pull out all of the errors and warnings lines from these 8 files into one single txt file.

I was able to build up the following command:
Code:for host in `cat hosts; do ssh -qo StrictHostKeyChecking=no $host "hostname; cd /path/to/file/; echo $host; grep -i 'error' *.log > error.txt";doneBut this stores a file named error.txt on each server, in that specific path. And that is the part I am not a fan of.

Now, I would like to run this command only on server1 and the outputs from greping the log files from each server to be stored in one single file in server1. I am not too happy in using scp transfers from each server and then cat all the files into one single file on server1.
So, is there a way I can change the code above so that, when I run the command on server1, it builds one single file on server1 with all the grep results from each server?

Thanks in advance!latest?d=yIl2AUoC8zA latest?i=g77P1N0XKm8:qEcGKZev88Y:F7zBnMy latest?i=g77P1N0XKm8:qEcGKZev88Y:V_sGLiP latest?d=qj6IDK7rITs latest?i=g77P1N0XKm8:qEcGKZev88Y:gIN9vFwg77P1N0XKm8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments