Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File last access date in UNIX (Solaris)

Posted on 2014-04-22
8
Medium Priority
?
1,014 Views
Last Modified: 2014-04-24
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
Comment
Question by:fireblood
8 Comments
 
LVL 22

Assisted Solution

by:robocat
robocat earned 150 total points
ID: 40017078
Why not modify the access time of the file back to the value you just read? Of course assuming you have enough permissions.
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 450 total points
ID: 40017095
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
 
LVL 22

Accepted Solution

by:
Brian Utterback earned 900 total points
ID: 40017171
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:Brian Utterback
ID: 40017178
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
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40017413
@blu - Works fine in Linux for me as well, did you test Solaris?
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 40017924
My test was on Solaris.
0
 

Author Closing Comment

by:fireblood
ID: 40020431
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
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40020696
You're welcome!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question