Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

User Who Modified File

by softworkz (Monk)
on Sep 26, 2012 at 13:48 UTC ( #995770=perlquestion: print w/ replies, xml ) Need Help??
softworkz has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, We have a huge website with various depts and I have to capture the last 'owner' or 'modifier' of webpage files. Manually I can go in and look at the properties of each file and see who was the last user who modified it or created it, but there are like 350 files.... So far I can capture the created date/accessed date/modified date, but I can't seem to get the user? The net says it's impossible, but if I can go to the file manually and see, why can't I capture it with a script? Any thoughts or help? Thanks! ** Update: Sorry I forgot to specify, yes this is on a Windoze system...

Comment on User Who Modified File
Re: User Who Modified File
by roboticus (Canon) on Sep 26, 2012 at 14:01 UTC
Re: User Who Modified File
by tobyink (Abbot) on Sep 26, 2012 at 14:04 UTC

    What do you mean by "file"? Just a file on a (Unix-like) filesystem? If so, Perl's stat function returns a whole bunch of statistics on files, including the numeric user ID of the file's owner. The getpwuid function can convert that to the user name.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: User Who Modified File
by MidLifeXis (Prior) on Sep 26, 2012 at 15:02 UTC

    It sounds (from the terms being used) like you are on a Windows system. If, however, you are on a unix system, you should be aware of a few things.

    This only works (under unix) if the OS captures extended usage logs, or the edit method creates a new file. An append or a open+trunc+write does not change ownership of the file.

    usera$ grep groupa /etc/group groupa::1000:usera,userb usera$ touch foo usera$ chgrp groupa foo usera$ sudo chown userb foo usera$ ls -l foo -rw-rw-r-- 1 userb ... foo usera$ echo Hello World > foo usera$ ls -l foo -rw-rw-r-- 1 userb ... foo

    That is not saying that it cannot be done, just that classical unix will not give the correct expected answers in all cases.

    On a system with chown for non-superuser privileges, there are even more assumptions being made.

    --MidLifeXis

Re: User Who Modified File
by davido (Archbishop) on Sep 26, 2012 at 16:18 UTC

    Most VCS (Version Control Systems, or revision control, or whatever you want to call them) keep track of who made a commit. Git allows each user to configure a username, and an email address. Each git commit records the commit's author.

    I can't imagine a website with 350 files not using version control in 2012, so you probably just need to look at your commit history, and therein you'll find your answer. You are using version control, aren't you?


    Dave

Re: User Who Modified File
by rpnoble419 (Pilgrim) on Sep 26, 2012 at 18:22 UTC

    What type of files are you tracking? Are you tracking Office files? What about PDF files? Or are you tracking any file submitted?

    To track Office (2007=<) files you can query the internal XML file (docProp -> core.xml) for the lastModifiedBy and dcterms:modified flags. This will give you the date of modification and the actual name of the person you modified the file, not just the name of the person who uploaded the file to the CMS. These properties are st every time the file is touched.

    PDF files also have a document properties that can be queried by PDF::API2 using the $pdf->info(%infohash) function. Most of these properties have to be set when you create the document.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://995770]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-27 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls