Click to See Complete Forum and Search --> : Watching Directories


WhiteKnight
03-08-2007, 10:33 AM
Is there a simple way of watching a directory for changes and execute a script after a change is detected?

I thought of having a cron job that checks the specified directory every once in a while, but that doesn't seem elegant enough.

Right now im trying to create a directory for me to drop files to be printed into, so that i can print from systems which i do not have print drivers installed or whatnot.

TIA

ph34r
03-08-2007, 01:56 PM
cron and a touch file (for referencing when the cron job was last run) and find with the ctime args are your friend.

Edit - something else that may work would be a script to upload the file to via a web interface, which would print it and then delete/remove the temp file.

michaelk
03-08-2007, 06:42 PM
http://freshmeat.net/projects/watchd/

WhiteKnight
03-09-2007, 07:03 AM
the deamon looks neat. giving it a go.

having to use scripts is wat i want to avoid. as i hope to be able to send files from devices like my mobile phone via bluetooth, which obviously cant run any scripts...

hotcold
03-09-2007, 07:38 AM
Hi.

The item below is on a Xandros system I use. I don't know if it is generally available, but it may be useful as an alternative ... cheers, hotcold

Package: dnotify
Description: Execute a command when the contents of a directory change
dnotify is a simple program based on Linux kernel 2.4.19+'s dnotify
API. dnotify can execute a specified command each time the content
of a specific directory changes. It is run from the command line and
takes two arguments: one or more directories to monitor and a command
to execute whenever a directory has changed. Options control what
events to trigger on: when a file was read in the directory, when one
was created, deleted and so on.

WhiteKnight
03-09-2007, 10:40 AM
yup... dnotify is in gentoo's portage tree, 1 more alternative to play with
way to go!
cheers!