Unlike the answer to this question (Can a bash script be hooked to a file?) I want to be able to see content of files that haven't been created yet as or after they are created. I don't know when they will be created or what they will be named. That solution is for a specific file and actually mentions in the question title creating a "hook" to a specific file. My question is different because I don't want to hook anything, and what I do want is not specific to a particular file. My question's title specifies "..as they are created" which should be a clue that the files I am interested in do not exist yet.
I have an application that users use to submit information from a website. My code creates output files when the user is finished. I want to be able to see the content of these files as they are created, similar to the way tail -f
works, but I don't know ahead of time what the filenames will be.
Is there a way to cat files as they are created or would I have to somehow create an endless loop that uses find
with the -newermt
flag
Something like this is the best I can come up with so far:
#!/bin/bash
# news.sh
while true
do
d=$(date +"%T Today")
sleep 10
find . -newermt "$d" -exec head {} +
done
For clarification, I don't necessarily need to tail the files. Once they are created and closed, they will not be re-opened. Existing files will never change and get a new modification time, and so I am not interested in them.
inotify
does appear to be the solution I am looking for – David Wilkins Feb 26 '14 at 19:48