2

I want to live tail from three different folders with certain files included & excluded.
Folder 1:

  • Path: /var/www/app/var/log/
  • Exclude only: file1.log & file2.log

Folder 2:

  • Path: /var/log/web/log/
  • Include only: error.log

Folder 3:

  • Path: /var/log/service/log/
  • Include only: app1.error.log & app2.error.log

How would I tail from three different folders with inclusion and exclusion of some files in one tail command?

tail -f ???

Tried so far

tail -f /var/www/app/var/log/!(file1,file2).log /var/log/web/log/error.log /var/log/service/log/{app1,app2}.log 

But this doesn't work. I feel need to use find + tail

2 Answers2

1

Use my answer to your not-that-different question on SU to create three find commands that will find the files you're after. Then:

{ find … -print0 ; find … -print0 ; find … -print0 ; } | xargs -r -0 tail -F

Notes:

  • -F because of this: How to do a tail -f of log rotated files?
  • find commands run just once. If a new file appears whose name would have been matched but didn't exist at the time, then tail will ignore it. In other words: when tail starts all of its arguments are fixed, the file-to-be is not among them.
  • If the results form finds exceed the limit then xarg will run more than one tail (by default not in parallel though). Certainly you don't want this. Hopefully your finds will find a reasonable number of files and the limit will not be exceeded.
  • find -print0 and xargs -r -0 are not portable. You tagged ; in Ubuntu they will work.
0

Tail all of the files you want... output each tail to a file... tail the new file.

tail -f /var/log/large.log > ~/full.log && tail -f /var/log/medium.log > ~/full.log && tail -f ~/full.log

you can run it as one command but it looks a lil funky at first... but you could run it in another tty if you wanted and just tail the full log where you want it to look good.