1834609 Members
2638 Online
110069 Solutions
New Discussion

access time of files

 
SOLVED
Go to solution
Stephen Young_1
Occasional Advisor

access time of files

Hi,

Has anybody got a shell script that can tell whether a file has been accessed in the last 10 minutes and then perform and action accordingly.

Cheers in advance
5 REPLIES 5
G. Vrijhoeven
Honored Contributor

Re: access time of files

Hi,

Try using the find command ( man find)
it should give you the option -newer file ( just create a new file every 10 minutes).

hope this will help

Gideon
federico_3
Honored Contributor

Re: access time of files

create a file with specified time ( for example 10 minutes ago)

touch -t 0111061615 file(YYMMDDhhmm YY are the last 2 digits of the year, MM The mounth, DD the day of the month, hh the hour and mm the minutes)

find DIR -type f -newer file -print


Federico
G. Vrijhoeven
Honored Contributor

Re: access time of files

Hi again.

The option frederico gave will work just at "a" for access time.

find DIR -type f -newer a file -print

Gideon
A. Clay Stephenson
Acclaimed Contributor

Re: access time of files

Hi Stephen:

Does anybody have a script? Does a hog like slop?

Here is my standard perl script for determining if a file has been modified,accessed, or changed in a given number of seconds.

Simply execute fileage.pl without arguments for a full usage message.

By the way, being perl, it runs on Windows as well as UNIX.

Regards, Clay
If it ain't broke, I can fix that.
Roger Baptiste
Honored Contributor
Solution

Re: access time of files

Hi,

Here's one:

***
NOW=`date +%H%M`
ACC=`ll -u $1 |awk '{print $8}' |sed 's/://'`
CHECK=`"echo $ACC-$NOW"|bc`
if [ $CHECK -le 10 ]
then
echo "YES, I was peered into"
else
echo "Nobody pryed into me"
fi

***

I just typed it in. There may be some gaps in the date logic, but the flow is right.

-raj
Take it easy.