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

Hi,
- I am trying to write a PERL script to monitor file changes on a particular directory of interest

- the files are on a Windows server

- i am planning to schedule the perl script to run a couple of times a day using the Windows Scheduler.

Now, how can i find out in perl which user modified a file?

i tried using the 'stat' function, but it does not give me the information as to which user modified it!

The Win32::LoginName() command is the closest to what i want (i believe!) but i guess it would give the current user as which the scheduled task is logged on and probably not the actual user who is modifying a file!

Any help/suggestions?

Thanks
  • Comment on Finding out which user modified a file on a server...

Replies are listed 'Best First'.
Re: Finding out which user modified a file on a server...
by Fletch (Bishop) on Jun 30, 2008 at 15:58 UTC

    Most filesystems only record when a file was modified (and only the last time it was at that). If you need more information like who did what you're moving into the realm of revision control and will need to go through more than just the "normal" file open/read/write/close operations in order to get changes tracked. You'd need to look into some form of SCM software such as git, mercurial, SVN, bzr (or at a minimum something like RCS, but . . . bleh), but all of those require cooperation from the user making changes and aren't going to just magically remember who's doing what to arbitrary files. If you have non-technical users the simplest option is to provide wrappers and tell the lusers to run make-change-to-foo before they make a change and done-changing-foo afterwards.

    I also want to say that I think ClearCase provided a filesystem view to their repository which might behave the way you want (where it remembers who makes what changes slightly more transparently), but it's commercial software with a good sized price tag and has a reputation of being kind of a pain to manage.

    Update: added note about CC.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Hi,
      Thank you very much for your reply!

      I get your point; but i am not expecting something that complicated (like a version control/revision history)

      I just want to find out this - at some point, when a file gets changed, i just want to find out 'who changed it' and i don't really want to know 'what change he did'.

      Also, would be really nice if i can register for a directory/file change event that would trigger my perl script or some sort of event handling or trigger mechanism to fire my script (i am afraid the scheduler in Windoes XP does not seem to support that feature! ). That way at least i need not have my script continuously polling the files to see if any changes have been done!

      Thanks
      Biswanath
Re: Finding out which user modified a file on a server...
by BrowserUk (Patriarch) on Jun 30, 2008 at 17:46 UTC

      Thanks a lot for the reply!

      but is there no way by which we can get the login id of the user who last modified a file? That sounds really wierd!


        but is there no way by which we can get the login id of the user who last modified a file?

        That information is simply not recorded by standard file systems. It might be recorded by some specialist journaling filesystems, but I do not know of any.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Finding out which user modified a file on a server... (audit)
by tye (Sage) on Jul 01, 2008 at 00:58 UTC

    This will be vague and also not Perl-related, but... You can enable auditing (the global setting that is turned off by default), and then set the permissions (ACLs) on the file to specify that you want to audit successful attempts to modify the file. Then you just look in the event log to see who modified the file when (only for changes to the file done /after/ you set up auditing, of course).

    - tye