Directory Access Monitoring
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Directory Access Monitoring




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Directory Access Monitoring  
Claudius Zingerli


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-05 11:20 PM

Dear NG,

Is there any way to get notified if someone moved a file into a
directory? I'm searching for something like:

handle=open(directory)
...
rc=select(handle);
if (rc>0) { do something }

My target is to write a program A that "listens" on a directory (like a
socket on a port). Another program B then moves a file into this
directory. Program A notices this and processes this file.

Does anyone know an API call or a solution for me? My program should run
at least on FreeBSD but Linux would also be nice. Is there any common
way to do that?


Thanks a lot!

Claudius

[dcoup readers: please ignore, my fault]





[ Post a follow-up to this message ]



    Re: Directory Access Monitoring  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-05 11:20 PM

On Sat, 19 Feb 2005 19:06:29 -0500, Claudius Zingerli wrote:

> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.

On linux look at /usr/src/linux/Documentation/dnotify.txt. FreeBSD
probably has something similar. There are also utility programs that will
execute a command in reponse to a directory changing. You might also
be able to simply open the directory of interest and fstat it every 5
seconds to see if mtime has changed. I've never done any of this however.

Mike





[ Post a follow-up to this message ]



    Re: Directory Access Monitoring  
Heiner Steven


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-05 11:20 PM

Claudius Zingerli wrote:
> Dear NG,
>
> Is there any way to get notified if someone moved a file into a
> directory? I'm searching for something like:
>
> handle=open(directory)
> ...
> rc=select(handle);
> if (rc>0) { do something }
>
> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.
>
> Does anyone know an API call or a solution for me? My program should run
> at least on FreeBSD but Linux would also be nice. Is there any common
> way to do that?

I think there is no common (at least no standard) way to monitor
a directory for changes.

Since this is a common problem, there are different solutions, though.
You could e.g.

o  use FAM (File Access Monitoring)
o  Solaris event ports (starting with Solaris 10)

Heiner
--
___ _
/ __| |_ _____ _____ _ _     Heiner STEVEN <heiner.steven@nexgo.de>
\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/





[ Post a follow-up to this message ]



    Re: Directory Access Monitoring  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-05 11:20 PM

Claudius Zingerli <msnews@zeuz.ch> wrote:
# Dear NG,
#
# Is there any way to get notified if someone moved a file into a
# directory? I'm searching for something like:

If you have kqueue on your system (BSD and perhaps ported to some Linuxes),
open the directory read-only, then set a kevent to watch the inode of the
open file. Changes to the directory will change the inode and be reported
back to you.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Quit killing people. That's high profile.





[ Post a follow-up to this message ]



    Re: Directory Access Monitoring  
Markus Elfring


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-20-05 11:20 PM

> My target is to write a program A that "listens" on a directory (like a
> socket on a port). Another program B then moves a file into this
> directory. Program A notices this and processes this file.
>
> Does anyone know an API call or a solution for me? My program should run
> at least on FreeBSD but Linux would also be nice. Is there any common
> way to do that?

Would you like to use the free tool "File Alteration Monitor"?
http://oss.sgi.com/projects/fam/faq.html#what_is_fam







[ Post a follow-up to this message ]



    Re: Directory Access Monitoring  
Claudius Zingerli


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-21-05 11:00 PM

Thanks for the many responses. I finally used kqueue and kevent in
FreeBSD and the fcntl-calls in Linux.


Claudius





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:43 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register