Link to home
Start Free TrialLog in
Avatar of Earthworm
Earthworm

asked on

Use stdout as argument of next command

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...
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

Or a shorter version

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

ASKER

Thanks, I knew it would be easy!