HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Files 15 mins older than sysdate

 
SOLVED
Go to solution
Yvonne Butler
Regular Advisor

Files 15 mins older than sysdate

Hi

Does anyone know how I can get find to give me a list of files within a directory that is 15 minutes or more older that the current system date? Or does anyone have a handy little script that does this? More than this I need really a count of how many files are within a directory that are 15 minutes or more older than the system date.

Thanks
13 REPLIES
Mel Burslan
Honored Contributor

Re: Files 15 mins older than sysdate

touch -t MMDDhhmm /tmp/dummyfile # where hhmm is timestamp of 15 minutes ago

cd /my/directory
find ./ -newer /tmp/dummyfile | wc -l


hope this helps
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi Yvonne:

You can use:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ <= (15/(60*60*24))},$path)' /dirname

If you omit the "/dirname" argument, your current working directory will be examined.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Files 15 mins older than sysdate

Here's a pseudo-script, you'll need to do the translation:

get current time using date
manipulate that time by subtracting 15 minutes
use find with -older to find files matching
pipe results to "wc -l"


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi (again):

Oops, you want files _OLDER_ so:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ >= (15/(60*60*24))},$path)' /directory

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

The perl command doesn't seem to work:

Can't locate File/Find.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.

Patrick Wallek
Honored Contributor

Re: Files 15 mins older than sysdate

Mel's find command will work with 1 changes, since you want files OLDER than sysdate - 15 minutes.

find ./ ! -newer /tmp/dummyfile

Notice the '!' prior to the '-newer' to make it not newer than the /tmp/dummyfile.
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi Yvonne:

Perl 5.005 is OLD. If you want, update to a current (5.8.8 or later) version:

http://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi (one more time):

I'm sorry, NO POINTS FOR THIS CORRECTION, but for 15 _minutes_ use:

(15/(60*24))

NOT:

(15/(60*60*24))

...which represents 15 _seconds_

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

I'm trying to upgrade the Perl installed on this system but now I've hit another issue, for some reason the system isn't allowing me to swinstall anything, I get a message about not having permission for this operation when I'm root!

Anyway, once I've got this fixed and have installed the later version of Perl, I'll try again.
Ganesan R
Honored Contributor

Re: Files 15 mins older than sysdate

Hi,

Restart the swagentd daemon.

#/usr/sbin/swagentd -r
Best wishes,

Ganesh.
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

Hmm, that perl command doesn't seem to return the 15+ minutes older than sysdate count of files in the directory:

root: /oraother/dst/comms/outtray # ll
total 9616
-rw------- 1 dstdba dba 2417496 Feb 6 2008 core.0468
-rw------- 1 dstdba dba 2483032 Jan 31 2008 core.9416
-rw-r--r-- 1 dstdba dba 786 Feb 6 2008 sqlnet.log.0452
-rw-r--r-- 1 dstdba dba 832 Feb 6 2008 sqlnet.log.0456
-rw-r--r-- 1 dstdba dba 786 Feb 6 2008 sqlnet.log.0469
-rw-r--r-- 1 dstdba dba 786 Feb 6 2008 sqlnet.log.0471
-rw-r--r-- 1 dstdba dba 832 Feb 15 2008 sqlnet.log.2185
-rw-r--r-- 1 dstdba dba 786 Feb 15 2008 sqlnet.log.2187
-rw-r--r-- 1 dstdba dba 786 Jan 31 2008 sqlnet.log.9393
-rw-r--r-- 1 dstdba dba 786 Jan 31 2008 sqlnet.log.9412
-rw-r--r-- 1 dstdba dba 786 Jan 31 2008 sqlnet.log.9416
-rw-r--r-- 1 dstdba dba 832 Feb 5 2008 sqlnet.log.9805

root: /oraother/dst/comms/outtray # perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_&&-M_ >=(15/(60*24))},$path)' /oraother/dst/comms/outtray | wc -l
0

Any ideas?
James R. Ferguson
Acclaimed Contributor
Solution

Re: Files 15 mins older than sysdate

Hi Yvonne:

There are two problems here -- both mine!

First, it looks like in the second post I made I lost some whitespace. There is actually a warning that we could see:

# perl -MFile::Find -wle '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_&&-M_ >=(15/(60*24))},$path)'

Next, my original, math was horrible! FOr files older than 15-minutes we need:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ >= ((15*60)/(60*60*24))},$path)'

You will see that I haven't tried to factor in my head :-)

The '-M' tests the modification age of a file in the number of DAYS, so the expression represents that fraction of a DAY that is 15-minutes.

My apologies again, but at least your Perl is reasonably up-to-date now!

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

Thanks very much James, that revised Perl command does exactly what I need (with a "| wc -l" at the end).