how do you watch for an incoming file
Leslie Mikesell
les at chinet.chi.il.us
Thu Nov 30 05:15:59 AEST 1989
In article <5506 at hplabsb.HP.COM> quan at hplabsb.HP.COM (Suu Quan) writes:
>
> How do I write a C-program or shell script that will watch for
>the presence of a new file in a certain directory.
>
>Scenario : I expect a file to be sent to me -name possibly unknown- to a
>directory (callit /application/inputfile/). Since I do not know when it
>will arrive (ftp, rcp ... does not matter), I want to be notified of its
>presence as soon as possible but not burn any cpu in the mean time.
The cheapest operation would probably be to stat(2) the directory at
some interval, then use opendir(), readdir(), etc. to find the
filename when the st_mtime field changes.
For a shell approach you will have to read the directory but the
(generally) built-in echo command will do it.
#
cd dir
while :
do
FILES=`echo *`
if [ $FILES != "*" ]
then
# put your notify command here...
exit
fi
sleep 30
done
> But I would prefer a C-program or a script using a blocking command
> Any help is appreciated
That would require some help from the delivery program - for example writing
to a FIFO when the delivery is complete. In any case you might need to
guard against processing a partial file (i.e. the name has appeared but
the writer has not completed its output).
Les Mikesell
les at chinet.chi.il.us
More information about the Comp.unix.questions
mailing list