Tailing logs from different files into one single file

Hi

Please help me in finding a solution for tailing multiple log files and writing all of them into one common file.

I have 4 log files with same name in 4 different folders.
Whenever I post a Request - any one of these 4 log files gets updated with some log detail in the below format :

blah|blah|blah|blah|blah

ex:

/Top/Folder1/logfile.log
/Top/Folder2/logfile.log
/Top/Folder3/logfile.log
/Top/Folder4/logfile.log

Logging can happen in any of the above 4 logfile.log instances each time a request is sent to the Server.

I check if logging happens or not by tailing all the above 4 instances in 4 different windows which is very ineffective.

I want to make this simple by writing some script that will look up if any of the log files get updated whenever a request is sent & then write that line into one common file.

ex :

tail -f /Top/Folder1/logfile.log >> file.log
tail -f /Top/Folder2/logfile.log >> file.log
tail -f /Top/Folder3/logfile.log >> file.log
tail -f /Top/Folder4/logfile.log >> file.log

I want to tail only that common file each time to capture my Logs.

Thanks
S

one method can be to writer the script which look the modification time and if it is different from the last modified time then tail last four line of that log file into common log file.

Are you saying that your tail -f commands are ineffective? Is it that you actually need to put al of these into the background so that they are all running:-

tail -f /Top/Folder1/logfile.log >> file.log &
tail -f /Top/Folder2/logfile.log >> file.log &
tail -f /Top/Folder3/logfile.log >> file.log &
tail -f /Top/Folder4/logfile.log >> file.log &

What output are you getting in file.log and what's not?

Robin
Liverpool/Blackburn
UK

Have you considered multitail ?

Regards
Peasant.

Sorry, I meant to say that tailing all the 4 logs in 4 different windows is not an efective way to verify.

Yes I want to put them in Background and Only tail file.log
Is there a way I can write these tail cmds in one script & execute that script whenever I want

Sorry I am new to this & trying to learn

---------- Post updated at 11:31 AM ---------- Previous update was at 11:30 AM ----------

No I haven't. Could you please help me how to ?

---------- Post updated at 12:09 PM ---------- Previous update was at 11:31 AM ----------

Thanks All, the following works the way I want it

tail -f /Top/Folder1/logfile.log -f /Top/Folder2/logfile.log -f /Top/Folder3/logfile.log -f /Top/Folder4/logfile.log

BUT is there a way to tail all file.log files inside ALL the sub folders under /Top in just one line :

tail -f  /Top/*/file.log
  • --> All subfolders under /Top

Well, you could do it in two steps:-

for file in /Top/*/logfile.log
do
   logfiles="$logfiles -f $file"
done

if [ ! -z "$logfiles" ]  # Just in case none are found
then
   tail $logfiles        # Implicit -f already in the $logfiles variable
fi

If the file filename expansion becomes too long, you may hit problems and have to convert it a little.

Does this do what you need?

Robin