tools4j / unix4j

An implementation of Unix command line tools in Java.
unix4j.org
MIT License
236 stars 43 forks source link

Tail - File Monitor Funcitonality? #51

Closed aadrian closed 6 years ago

aadrian commented 6 years ago

Hi,

Any chance getting the file monitor functionality option for tail ? https://en.wikipedia.org/wiki/Tail_(Unix)#File_monitoring

Thank you.

terzerm commented 6 years ago

Hi

Thanks for your question. Unfortunately the 'tail -f' feature does not fit very well into the unix4j philosophy of chaining commands. Hence we have no plans at the moment to implement this.

However a similar functionality can be found in Apache's Tailer: https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/input/Tailer.java

Hope this helps. Regards, Marco

aadrian commented 6 years ago

... does not fit very well into the unix4j philosophy of chaining commands.

How comes?

tail -f /var/log/file.log | grep search_term

is a very used pattern.

and the equivalent of "chaining commands" would look like:

Unix4j.tail(Tail.Options.f, "/var/log/file.log").grep(...)
terzerm commented 6 years ago

But the command blocks until you stop it with Ctrl-C --- how would you want to do this?

aadrian commented 6 years ago

But the command blocks until you stop it with Ctrl-C --- how would you want to do this?

https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/input/Tailer.java is also requires Threads or Executor.

terzerm commented 6 years ago

Yes --- and that does not fit well with the current very generic interface of unix4j. In particular to eventually execute the command you chose e.g. toStringList or other output methods. I am not worried about the thread, but about how to keep everything generic. I would have to somehow expose a "stop" method to abort the infinite tailing.

Sure this would be possible somehow but would likely require some changes in the current design. Unfortunately I don't have the resources to start such a project atm.