We help IT Professionals succeed at work.

Use stdout as argument of next command

Earthworm
Earthworm asked
on
I want to tail -f a log file. The application dynamicall names its log files using the date, so each time the app is run the log file looks something like "myapp-2008-01-18-18-29-17-686.log". There are many log files, but I know I just want to tail the last one. I have taken this approach to discover which is the latest:

$ ls -trC1 myapp*.log | tail -1

That displays to stdout the file I am interested in. I cannot figure out if it is possible to somehow pipe that or redirect it somehow as the ARGUMENT of another tail -f command. This does NOT work because the last tail command is just tailing stdin:

$ ls -trC1 myapp*.log | tail -1 | tail -f

Any ideas? I'm open to other suggestions, but I'd like to keep it simple and do it in one line instead of a script...
Comment
Watch Question

Data Warehouse / Database Architect
CERTIFIED EXPERT
Commented:
Hi Earthworm,

Piece of cake.  :)

tail -f ` ls -trC1 myapp*.log | tail -`


Good Luck,
Kent
CERTIFIED EXPERT
Top Expert 2007

Commented:
Or a shorter version

tail -f `ls -t mpapp*.log | head -1`

Author

Commented:
Thanks, I knew it would be easy!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.