Solved

Need script to remove files older than 5 minutes

Posted on 2007-03-25
7
558 Views
Last Modified: 2013-11-17
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
0
Comment
Question by:9thTee
7 Comments
 
LVL 19

Expert Comment

by:NickUpson
ID: 18788367
find /tmp -name poe*.pid -mmin 5 -exec '/bin/rm -f {} ;'
0
 

Author Comment

by:9thTee
ID: 18788412
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?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18788571
perl -e 'unlink $_ or warn $_ for grep  -M > 5/(24*60), <poe*.pid>'
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:9thTee
ID: 18788657
ozo, I am not sure what your perl script should do.  Can you please explain?

Thanks,
Mark
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18789459
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.
0
 

Author Comment

by:9thTee
ID: 18789811
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.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 18789828
Hmm.  Interesting that you don't have GNU find on your AIX system them.

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

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ubuntu not booting - How get past GRUB? 3 59
Install Predefined Certificate on Ubunto 4 48
bash file 10 51
Linux Desktop suggestion for Dell Inspiron 3043 13 55
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question