Hi All,

1)I want to watch a directiory in unix using a shell script.

2)In case any change happens to any of the files inside that

e.g new file creation
or new directory creation
or any file modification

we need an automated mail.
3)Mailing part i will take care
4)on the part of scheduling we can using any scheduler or use sleep
because the script will run twice a day.

i only wanted to know about the file modification alert part.

Any approach for this?

Thanks,
Deepak

i used perl once to copy the contents of a directory and place it in a variable and then to use that list of files later in the perl script

if you want i can fish that out for you to use

i used perl once to copy the contents of a directory and place it in a variable and then to use that list of files later in the perl script

if you want i can fish that out for you to use

can you share the same with me

I like the stat/diff idea!

Do you need to know what files have changed, or just IF they have changed?

I have a script that monitors a directory for changes, and then rsyncs it with another server, does some logging, etc... if any changes occur. To check for changes I store an 'md5sum' of the output of 'find'.

find /path/to/directory |md5sum

This probably wouldn't work for modification times though, so I think you're probably better off with the stat/diff thing. Here's a way to do it that works if there are spaces in your filenames:

find . | while IFS= read filename; do
  stat -c "%Y %n" "$filename"
done

Hope this helps!
-G

Salem's way of doing it is efficient and easier. I would just do what he said:

$ find . | xargs stat -c "%Y %n"
Then check for differences.

Salem, thanks for the link c: never heard of it before.

This article has been dead for over six months. Start a new discussion instead.