Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

modified file

by Anonymous Monk
on Sep 22, 2001 at 19:54 UTC ( [id://114066]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I would like to know if I can use perl to check if a file has been viewed. Basically if I write a letter and log out and the system admin looks at my letter or any other file I have how would I check for this activity using perl?

Replies are listed 'Best First'.
Re: modified file
by wog (Curate) on Sep 22, 2001 at 20:10 UTC
    On platforms where there is a timestamp for when a file was last viewed (includes most UNIX systems) you can check the access timestamp returned by stat or -A. Note that this timestamp can be manipulated, and that the sysadmin may be able to bypass the timestamping mechanism entirely.
      Good point wog, this is particularly true of backups. It is possible for the sysadmin to backup all your files, restore them to a different location and do whatever they want to the copies. This type of activity would leave no trail that you could follow.
      @a=split??,'just lose the ego and get involved!';
      for(split??,'afqtw{|~'){print $a[ord($_)-97]}
        Or, taking what you said a different way -- the sysadmin, doing the routine nightly backups, could throw the timestamp off too.. leaving you unsure if it was an automated process which touched the file, or a person manually looking at it.

        Backups, tripwire, the "locate" DB, and several other nightly processes can all interfere with it.
        -Eric
Re: modified file
by suaveant (Parson) on Sep 22, 2001 at 20:20 UTC
    -A 'file' will give you how many days ago file was accessed... maybe better for reading would be to use the stat() function to get the access time in seconds since the epoch (same type of output as time()) here is a simple script...
    #!/usr/bin/perl print qq` Usage: $0 <files to check> `; for(@ARGV) { printf("%24s was last accessed on %s\n",$_,scalar localtime((stat +$_)[8])); }

                    - Ant
                    - Some of my best work - Fish Dinner

Re: modified file
by czarfred (Beadle) on Sep 22, 2001 at 20:44 UTC
    just for variety...

    #!/usr/bin/perl -w use strict; die "Usage: $0 <files> ...\n" unless @ARGV; my $res = map { printf("%24s last accessed on %s.\n", $_, scalar localtime( (stat)[8] )); } @ARGV;
Re: modified file
by CubicSpline (Friar) on Sep 22, 2001 at 20:17 UTC
    Checkout perlfunc:stat which will give you the status of a filehandle. This includes modify/access times, permissions, etc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found