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...

#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;

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?

This is a start, you get to work on the other details I could not see.

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

OK so if I put this in...

#!/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...

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.

#!/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

OK thanks so my script now looks like this...

#!/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 :slight_smile:

But in the mean time I think this script is almost done�? apart from the print formatting to the output file.

Please provide a sample of what you want the output to look like.

If it was a directory listing format ...

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

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