Comments on Triggering Commands On File/Directory Changes With Incron on Debian Etch

Triggering Commands On File/Directory Changes With Incron This guide shows how you can install and use incron on a Debian Etch system. Incron is similar to cron, but instead of running commands based on time, it can trigger commands when file or directory events occur (e.g. a file modification, changes of permissions, etc.).

10 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: A_Biondi

You've forgotten to say that the kernel must be with inotify compiled in, oterwise incron won't work...

By: UngaMan

Hi.

 If you want to process some a file recently created, be careful in testing the IN_CREATE and IN_CLOSE_WRITE events after making it live.

It seems that IN_CREATE reacts when the file descriptor is created and not necessarily when the file has been fully filled.

I tried to make an automated copy of some long files created by a third-party software. It happened that the 3rd party-software created the descriptor but took its time to write the content from the buffer to the file. So incrond reacted to the newly created filename and performed the operation commanded by my script but the files were empty (288 bytes). After having realized that, I changed the IN_CREATE for IN_CLOSE_WRITE in order to give the right time. Now my script works nice.

 Great article you have here and thanks for posting it!

By: ~A!

Wanted to stop in and say thanks. This comment saved me a lot of heartache.

By: Anonymous

Thank you!! This was very helpful. Saved me a lot of time and frustration.

By: etkopa

Indeed, most of the time you want to use IN_CLOSE_WRITE. But be careful - some programs might close the file, and yet re-open it for more writing. There is not easy way to determine when the file has been written in full in some cases. A little sleep might help here as well, bit this is only w workaround really.

By: Chasalin

Yes, it is obvious

Yes, it's so obvious you might forget it.

In the demo, the /tmp/ dir is watched and changes are echoed.

Don't make the mistake I made to pipe that echo to the mail command.

It will make temp files and loop ;)

By: Stav61

We have some rather large files being dropped in to an ftp. We would like some scripts to initiate work on the files once the files are done uploading not when they are created. In addition there is more than one file going up. Any one have any ideas?  we would like the simplest solution considering the Perl scripts enacting on the files are pretty robust. We could edit the script files and iterate through the watched folder every time a file goes up to make sure the file count is right however that can fluctuate. Any help would be greatly appreciated.

Stav

By: Stavros Aloizos

You can variabilize the file name and port it to where ever you would like to send it or run whatever command you would like.

 /directory/being/watched IN_CLOSE_WRITE,IN_NO_LOOP  mv $@/$# /directory/for/working/$#

This would be initiated at the end of the completion of uploading of a particular file (name) to a particular folder. What’s good about this method is that individual file is grabbed when it finishes and worked on. Without it affecting the other contents of the directory and other files being transferred.

 

By: Annon

I can't believe it's taken so long to come across this comment! Thank you

By: janl

Hi,

with IN_CREATE I get for $# not the filename.jpg but filename.jpg.part

Tried it withIN_ALL_EVENTS and got filename.jpg.part in almost all instances.

It works with IN_MOVED_T.

Is there a setting/parameter that prevents $# to give back the name of the temporary filename.jpg.part ?

Regards,

Jan