continiously listen to the file location

Hi guys

i have been asked to write a program that would listen to a disk location in linux/solaris and when ever a file was inserted into the location, the service/program that i am supposed to write should automatically read it and upload the contents to the Database.

readinghe file and uploading is not a problem BUT my problem is how do i continiously listen to the disk and know when a file was inserted.

do u'll guys know of any such mechanism that could work for linux/solaris platforms.
inotify on Linux -- see the inotify(7) man page. There is no equivalent on Solaris.
Is this for some sort of poor-man's distributed communications mechanism by any chance? Why do you need to do this?
Would the file have a specific name? Or do you need to check for any file ?
Would the file have a specific name? Or do you need to check for any file ?

it could be any file.

Why do you need to do this?

for obvious reasons. assume u need to upload a comma separated file to a database. and assume that file is written by another program to this location.

isnt this an practical case. i dont think its a hypothetical one
I would consider it an impractical use case and a horrible hack.

It's poor-man's interprocess communication or, if on a shared file system, poor-man's distributed communication. A more modern way of approaching the problem would be to use a messaging system or client/server approach. You could use ActiveMQ or Qpid (messaging), OmniORB or Mico (CORBA), Axis2/C (SOAP), xmlrpc-c (XML-RPC), cgicc (HTTP CGI), Boost Asio (roll-your-own network protocol) or myriad other software products for this. I've just listed the free ones I know off the top of my head.

What you are attempting to do is used far too frequently and it *sucks* to maintain.

The number one problem with this method is that, without lots of cooperation from the other program, this is absolutely no way to tell when the file is completely written to the directory. Once you've spend the time addressing this issue, there are other, less obvious ones to address. Once you have addressed all of those issues, you might as well have spent the time to learn one of the tools listed above. In the end you will have written less code and have a more robust system for uploading data to your database.

Not that I am bitter about having had to fix systems like what you are proposing or anything. :-)
Topic archived. No new replies allowed.