user1293098
user1293098

Reputation: 3

Problems trying to 'tail' latest log files

I was wondering if someone can help me out - working on a bit of a problem and I seem to be getting nowhere. Ye olde Google isn't throwing up much either..

Basically I have a variety of server log files (server.log, full.log to name a few) and they're all buried and archived into directories in /logs, eg: 26_03_2012_11-17 & 26_03_2012_09-17. The script I'm trying to create would ideally work with 'tail.sh problems' and it would find the most recent problems.log file and 'tail -f' it. Unfortunately I've been struggling, trying to figure out how to tail -f the most recent server.log, problems.log etc.

What I have at the moment works (I think) when you are in one of those date directories, I just need it to search recursively to find the most recent version of that file.

tail -f `ls -tr | grep full.log | tail`

Any help is greatly appreciated

Upvotes: 0

Views: 935

Answers (1)

beny23
beny23

Reputation: 35018

How about:

tail -f $( ls -1tr `find /my/root/log/dir -name "*.log"` | tail -1 )

This does tail -f on the most recent log file. If you want tail -f on the most recent server.log:

tail -f $( ls -1tr `find /my/root/log/dir -name "server.log"` | tail -1 )

Upvotes: 1

Related Questions