Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

File last access date in UNIX (Solaris)

I'm using the stat function in perl to obtain an array of elements that describe the files being examined.  One of the elements in the array is the file's date of last access made by anyone.  However, the act of reading the file's date of last access changes that value to the date/time that the file's date of last access is read, which is the current date and time.  Is there a way to read the file's date of last access without changing it in the process?
0
fireblood
Asked:
fireblood
3 Solutions
 
robocatCommented:
Why not modify the access time of the file back to the value you just read? Of course assuming you have enough permissions.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Using stat on a file handle in perl is not changing accessed, modified or changed timestamps. How are you reading the access timestamp of a file?
0
 
Brian UtterbackPrinciple Software EngineerCommented:
You must be doing something other than just running stat on the file. I attached a test perl script and here is what I get when I run it:

# ~/stat.pl
Create file and display the access time
-rw-r--r--   1         10 Apr 23 07:01 testfile

Get the atime and display it
Apr 23 07:01:46

Wait a while

Get the atime again and display it
Apr 23 07:01:46

What is the access time now?
-rw-r--r--   1          10 Apr 23 07:01 testfile

Now we really access it then display access time.
-rw-r--r--   1          10 Apr 23 07:02 testfile


As you can see, the access time did not update when run stat on the file.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Brian UtterbackPrinciple Software EngineerCommented:
Oops, somehow I missed the file. Here it is. I had to change the extension becase EE doesn't accept files with extension .pl.

stat.sh
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
@blu - Works fine in Linux for me as well, did you test Solaris?
0
 
Brian UtterbackPrinciple Software EngineerCommented:
My test was on Solaris.
0
 
firebloodSAS ProgrammerAuthor Commented:
Thanks to the three of you, the key insight for me here was that I was asking for a workaround to a problem that didn't exist.  My code was accessing the files in a way that I didn't recognize, and when you made it clear that just doing a stat would not change the last access time stamp I went back and then confirmed that you were correct.  Thanks very much to all three.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You're welcome!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now