VicBalta has asked for the wisdom of the Perl Monks concerning the following question:

HI

My question is about monitoring a directory. I have two directories on different boxes that are the same. The only problem is that they are both not updated at the same time. So I want to make a program that will monitor the directory that is going to be changed. And when a change happens it will make the changes to the other box. i.e. adding files, deleting folders. I know how to do this part but I want to know what is the best way to monitor a directory to see if any thing has changed. So i can have a process that is constantly monitoring the changeable directory. Also would it be able to monitor if any permission have been changed?

Any would be great thanks

Victor

Replies are listed 'Best First'.
Re: Monitoring Directories for changes
by hopes (Friar) on Dec 08, 2001 at 00:08 UTC
    You can use the stat built-in funtion to detect when a directory changes.
    Hope this helps

    Hopes
    $_=$,=q,\,@4O,,s,^$,$\,,s,s,^,b9,s, $_^=q,$\^-]!,,print
Re: Monitoring Directories for changes
by perrin (Chancellor) on Dec 08, 2001 at 00:44 UTC
    If possible, use rsync for this rather than a homegrown perl thing. It will be more efficient.
      Or you could always use merlyn's perl rsync ;-)

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"

        Link please?
Re: Monitoring Directories for changes
by belg4mit (Prior) on Dec 07, 2001 at 23:58 UTC
    Just watch and compare -M (see perlfunc not perlop). I don't recall if this will catch permission changes since this happen to the inode and not the file. However that inode is still "owned" by the directory so in theory it should...

    --
    perl -p -e "s/(?:\w);([st])/'\$1/mg"