Link to home
Start Free TrialLog in
Avatar of 9thTee
9thTee

asked on

Need script to remove files older than 5 minutes

Hi,
I need a script that will look at certain files and if the file is over 5 minutes old, remove it.  
The files are located in /var/tmp
The file names can vary but always start with "poe" and ends with ".pid" so the script should look for files named "poe*.pid".  An example name would be "poet0001.pid" or "poepp0002.pid".
I will be running this via cron on a IBM AIX machine.

Any help would be appreciated.
Thanks,
Mark
Avatar of Nick Upson
Nick Upson
Flag of United Kingdom of Great Britain and Northern Ireland image

find /tmp -name poe*.pid -mmin 5 -exec '/bin/rm -f {} ;'
Avatar of 9thTee
9thTee

ASKER

Unfortunately, it appears that IBM AIX does not have the -mmin parameter for find...
I get: find: 0652-017 -mmin is not a valid option.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 9thTee

ASKER

ozo, I am not sure what your perl script should do.  Can you please explain?

Thanks,
Mark
ozo's Perl script does what you requested, although I'd change it to specify the path, ie:

perl -e 'unlink $_ or warn $_ for grep  -M > 5/(24*60), </var/tmp/poe*.pid>'

Removes all /var/tmp/poe*.pid files that are older the 5 minutes.

BTW, why did you post an AIX question in the Linux group?  As you saw from the first answer, GNU find (and all GNU versions of common commands) has very useful extensions like the mmin.
Avatar of 9thTee

ASKER

Ahhh, ok, it does work.  I just did not see something that said delete...

I am running AIX 5.1L which is AIX affinity with Linux.  I post in Linux area (in addition to AIX) because nearly all Linux suggestions works on AIX.  Since there are more Linux folks out there than AIX, I usually get faster responses when I post in the Limux area.

Hmm.  Interesting that you don't have GNU find on your AIX system them.

Remember that in Unix, delete = rm which is really unlink.