I second this: inotify-tools is a fantastic package (written by an
Aussie, no less) that's very easy to wrap in shell script.

The only problem i've ever had with inotifywait was when I recursively
ran it over a directory with about 30 subdirectories and 80,000 files.
It took *ages* to start, and segfaulted often.

That said, on shallow directories with less than 1000 files it should
cope adequately.

If you don't have a recent kernel and are looking for something with
maximum compatibility, try using rsync with the --list-only argument,
and parsing it's output with diff.

Lindsay


On Mon, Mar 10, 2008 at 5:45 AM, Massimiliano Fantuzzi
<[EMAIL PROTECTED]> wrote:
> Hi Guys !
>  I really agree with all those methods, they are scriptable and efficient,
>  but the best choice at present day is another...
>  Is the choice for userland utilities (inotify-tools) to the new kernel
>  module inotify.
>
>  It gives granular auditing for files, directories and sockets in general,
>  and doesn't introduce prestational overhead, as script may do. sure, you
>  have to run a 2.6 kernel, i admit ... here is an example sscript from
>  project's homepage:
>  inotifywait example 1
>  #!/bin/sh # A slightly complex but actually useful example inotifywait -mrq
>  --timefmt '%d/%m/%y %H:%M' --format '%T %f' \ -e close_write /home/billy |
>  while read date time file; do rsync /home/billy/${file}
>  rsync://[EMAIL PROTECTED]/backup/${file} && \ echo "At ${time} on ${date},
>  file ${file} was backed up via rsync" done This may be the most efficient
>  way to block for changes on files from a shell script.If you don't specify
>  which event you want to catch, all will be caught, and the event which
>  occurred is output on stdout.inotifywait example 2
>  #!/bin/sh  EVENT=$(inotifywait --format '%e' ~/file1) [ $? != 0 ] && exit [
>  "$EVENT" = "MODIFY" ] && echo 'file modified!' [ "$EVENT" = "DELETE_SELF" ]
>  && echo 'file deleted!' # etc... inotifywait will return true if an event
>  you asked for is caught. If an event you didn't ask for is caught, it will
>  return false; this generally occurs if you listen to a file on a particular
>  partition and the partition is subsequently unmounted, or if you listen for
>  a specific event and the file is deleted before that event occurs.
>  http://en.wikipedia.org/wiki/Inotify     &
>  http://inotify-tools.sourceforge.net/
>
>  there are more and more applications for this, check it out and abandon
>  find,test and diffs...
>  maybe try perl, dunno, but also give a try to inotify (I REPEAT: IT IS A
>  OFFICIAL KERNEL MODULE)
>
>
>  On Sun, Mar 9, 2008 at 10:10 AM, ken Foskey <[EMAIL PROTECTED]> wrote:
>
>  > On Sun, 2008-03-09 at 18:40 +1100, david wrote:
>  > > #!/bin/bash
>  > > if [ -N /some/directory/ ] ; then
>  > >         echo "change"
>  > > else
>  > >         echo "no change"
>  > > fi
>  > >
>  > > The object is to identify changes within a directory. This tells me if
>  > > there are any new or deleted files, but not if files within the
>  > > directory are modified.
>  > >
>  > > Is there a trivial way to do it?
>  >
>  > In script something like this:
>  >
>  > ls -l >file1
>  > ls -l >file2
>  >
>  > diff file1 file2
>  >
>  > In perl
>  >
>  > use File::Monitor;
>  >


-- 
http://slug.org.au/ (the Sydney Linux Users Group)
http://holmwood.id.au/~lindsay/ (me)
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to