Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

tail -f bar/somefile.log would fail immediately when somefile.log does not exist. How do I make tail indefinitely wait for that file to be created (which will happen in a few moments)?

Update: using -F, I see:

tail: cannot open `bar/somefile.log' for reading: No such file or directory
tail: cannot watch parent directory of `bar/somefile.log': No such file or directory

because bar does't exist yet (it will be created in a few moments). when bar was created, and somefile.log was touched, tail didn't pick up the changes at all.

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

This works:

while ! tail -f bar/somefile.log ; do sleep 1 ; done
share|improve this answer
    
this is what finally worked for me (for missing parent directory cases). –  Sridhar Ratnakumar Feb 20 '12 at 19:48
add comment

You're not mentioning which OS you need it for, but tailon linux has the --retry and --follow options that will do just that;

tail --retry --follow=name somefile.log
share|improve this answer
1  
thanks, or tail -F somefile.log. but then, tail fails for a different reason (i've updated my question) –  Sridhar Ratnakumar Feb 20 '12 at 19:35
add comment

I came across this problem recently and wrote https://github.com/blackfoundry/tailer to solve the problem. You can pass shell globs to the script, and it will keep retrying that glob and start tailing each file it finds.

share|improve this answer
add comment

Create the file first:

touch somefile ; tail -f somefile
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.