Last Accessed Time Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Last Accessed Time Script
# 1  
Old 05-11-2010
Last Accessed Time Script

Hi I want a shell script that will give me a list of files which were last accessed over a specific time ago and want it to use a variable so I can do this...

Rought Example...

Code:
#Input time in bracket for how many months.
MONTHSAGO="13"

#Specify the Top Level Directory path you want to 
DIR="/Share_Points/"

#Specify the output filename
FILENAME="Files_For_Archiving"

Script goes off checks the entire /Share_Points for any file that was last accessed over 13 months ago.

Compiles them into a list with the access date and path to file;

Code:
Access Date     File
01-01-2008      /Share_Points/Accounts/Reports/2008_Report.XLS


I have no idea on how to achieve this and would absolutely love it if someone could help?

Last edited by Scott; 05-11-2010 at 02:25 PM.. Reason: Code tags, please...
# 2  
Old 05-11-2010
This is a start, you get to work on the other details I could not see.

Code:
days=%(( $MONTHSAGO * 30 ))
find $DIR -type f  -atime +${days} \; > $FILENAME

# 3  
Old 05-11-2010
OK so if I put this in...

Code:
#!/bin/bash
## File Access Report
## Only edit the next 3 lines.
#Days ago to search
DAYS="365"
#TLD path you want to search
DIR="/Macintosh HD/"
#Output filename
FILENAME="/Files_For_Archiving.txt"
#
find $DIR -type f -atime +${DAYS} \; > $FILENAME

I get the following result...

Quote:
find: ;: unknown option
# 4  
Old 05-11-2010
Suddenly you directory name contains space characters and must be quoted.
Check thoroughly. The "last accessed time" is pretty volatile and gets changed by reading or changing a file. Some backup software changes that timestamp.

To keep you moving: The script so far produces a list of files for consideration.

Code:
#!/bin/bash
## File Access Report
## Only edit the next 3 lines.
#Days ago to search
DAYS="365"
#TLD path you want to search
DIR="/Macintosh HD/"
#Output filename
FILENAME="/Files_For_Archiving.txt"
#
find "${DIR}" -type f -atime +${DAYS} -print > $FILENAME

# 5  
Old 05-12-2010
OK thanks so my script now looks like this...

Code:
#!/bin/bash
## File Access Report
## Only edit the next 3 lines.
#Days ago to search
DAYS="365"
#TLD path you want to search
DIR="/Volumes/Macintosh HD/Users/"
#Output filename
FILENAME="/Files_For_Archiving.txt"
#
find "${DIR}" -type f -atime +${DAYS}  -printf FORMAT %Ak > $FILENAME

I am trying to use the print command to output the results formatted with a timestamp to my Variable Filename.

This doesn't seem to work or at lest my understanding the argument -print in the find command man page is off track?

Also I understand that backup software may alter the access timestamp but unless I have some long script that compares the <atime> with <mtime> I am unsure what to do. It a policy for archival, what I want to do is compile a list of human readable files (with paths to the file) of files over Xdays old which will mean they get archived off to tape.

If anyone has a better solution I am all ears :-)

But in the mean time I think this script is almost doneż? apart from the print formatting to the output file.
# 6  
Old 05-12-2010
Please provide a sample of what you want the output to look like.

If it was a directory listing format ...

Code:
find "${DIR}" -type f -atime +${DAYS}  -exec ls -lad {} \; > $FILENAME

# 7  
Old 05-12-2010
Thanks

i want the format to be...

TimeStamp of last (Access/Modify) <Space> FilePath

e.g:

01/12/2009 /Volumes/Data_RAID/Sharepoints/Accounts/some old report.xls
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File shows in ls but cannot be accessed

I can do an ls -l CD* and see the following CDTEST userA RW RW R and I an logged on as userA. But if I do an ls -l the file does not appear. If I do a vi CDTEST it tries to create a new file named CDTEST. If I do a mv or rm I get the message no file of name CDTEST found. Any idea what is going on.... (3 Replies)
Discussion started by: LeeT
3 Replies

2. UNIX for Advanced & Expert Users

Track the files accessed by a script.

How can i track all the files accessed by script. The script is supposed to bring up my application and this script is just the main script which inturn calls another scripts and executable. I need to know all the the files this main script calls and the files accessed by all the other scripts... (2 Replies)
Discussion started by: chacko193
2 Replies

3. Shell Programming and Scripting

Ftp script hangs for first time,but works every second time

Hi I have an ftp script which works fine when i execute through a test scheduler(UC4), but when i run it through the prod scheduler(UC4), it hungs indefinetely, when we cancel the job and re-run it it works perfectly fine. here is the code,, any idea why this is happening ???? ... (1 Reply)
Discussion started by: selvankj
1 Replies

4. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

5. UNIX for Dummies Questions & Answers

Searching files by last accessed time

How can I search for files by last accessed time? I want to see files accessed in the last 24 hours, for example...or even less time, maybe in the last 3 hours? Thank you in advance, Trellot (4 Replies)
Discussion started by: Trellot
4 Replies

6. Shell Programming and Scripting

File Accessed Alarm ??

Hey, I want to ask a simple Question.... How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed... (16 Replies)
Discussion started by: varungupta
16 Replies

7. AIX

File Accessed Alarm ??

Hey, I want to ask a simple Question.... How would I be able to come to know that files/directoires in a Parent directory has been accessed (means contents of the file has been just viewed) by the user(s) in a group ? and mail the name(s) of those files/directories which has been accessed... (1 Reply)
Discussion started by: varungupta
1 Replies

8. Shell Programming and Scripting

Can we get the list of users who accessed a file

Hi all, I will thankful if anybody helps me in finding out the users who accessed any of our files. Thanks in advance Chanakya (2 Replies)
Discussion started by: Chanakya.m
2 Replies

9. Shell Programming and Scripting

how to know which login file is being accessed

when unix is logged in it access some login file depending on the shell like .cshrc , .login , .vimrc , .bashrc how can we know which is being access in a perticular unix flavor. (1 Reply)
Discussion started by: useless79
1 Replies

10. Shell Programming and Scripting

getting last accessed and modified time together

actually, i'm making an Intrusion Detection System for education purpose (for project) using Bourne shell. The problem I get in that is:- 1. My application should check if there's some modification or alteration in the directory. 2, For that thing, I need to have every attribute of file and... (1 Reply)
Discussion started by: raku05
1 Replies
Login or Register to Ask a Question