.comment-link {margin-left:.6em;}

J. Daniel Ashton

www.flickr.com
This is a Flickr badge showing public photos from jdashton. Make your own badge here.
Whatever your hand finds to do, do it with all your might, —Ecclesiastes 9:10a NIV
The LORD God has told us what is right and what he demands:
"See that justice is done,
let mercy be your first concern,
and humbly obey your God." —Micah 6:8, CEV
With all your heart you must trust the LORD and not your own judgment.
Always let Him lead you, and He will clear the road for you to follow. —Proverbs 3:5,6 CEV

see also — My Homepage

My Photo
Name: Daniel Ashton
Location: Germantown, Maryland, United States


Any links with a dashed underscore probably point to Amazon.com

Sunday, February 12, 2006

How to tail log files

[File under: too-technical, unix-tricks]

I spent some time researching how to tail all the log files in and under my log directory. I'm blogging about it here in hopes that it will be useful to someone, and in hopes that I'll not forget it when I need it next!

Several of the log files contain non-printable characters, so I had to find a way to discriminate between binary and text files. I played around with using the file command, but I couldn't find a way to use its analysis within a single command-line.

This is what I finally wound up with:
find . -type f -not -name \*\.deflate_log\* -exec grep -Il . {} \; | xargs tail -F

Trying to translate into English, this is what I think it does: find . gives a list of all files in this subdirectory and its subdirectories. -type f specifies only plain files, as opposed to subdirectories and links. (I think.) -not -name \*\.deflate_log\* removes files with .deflate_log anywhere in their filenames: I believe the deflate mechanism is working, so I don't want to tail those logfiles. -exec grep -Il . {} \; tells the find program to pass the filename to grep The -I tells grep to ignore binary files, and the l tells it to return only the name of files that match, i.e. all text files.

Finally, the remaining filenames are passed to xargs, which then spawns a tail -F command to do the actual work.

Can you see a cleaner way to get the job done? Please tell me!

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home