Solved

Need script to remove files older than 5 minutes

Posted on 2007-03-25
7
552 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now