Need a cron shell script to remove files from directory after certain time...


I need to get a script working that can be CRON'ed to run nightly and look into specific directories and remove any files matching:

*PID.log as the end-name of the file and who's time-stamp is older than 48 hours.

The log directory is in 4 different environments, and I want to make use of our internal script to figure out the directory location...

It can be done with:

# cfgattr get production APPLTMPpath
# cfgattr get development APPLTMPpath
# cfgattr get testing APPLTMPpath    
# cfgattr get training APPLTMPpath

So I want a shell script to go into each of our environments, look into the "appltmp" folder and delete any *PID.LOG that is older than 48 hours.

How could one get this working?

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mirdeAuthor Commented:
These are LOG files that we generate with our application that we want to keep clean in the different directories, anything over 48 hours gone.

Progress RDBMS.
for i in /usr1/logs/ /usr2/devel_logs/ /usr4/test_logs/ /usr3/train_logs/appltmp; do
  /usr/bin/find ${i}appltmp -name "*PID.log" -mtime +2 -exec /usr/bin/rm {} \;

Stick that in your cron and you should be good to go. You could choose to have the list of directories in a file and feed that to your for loop with cat, e.g. for i in `cat dirs.txt`; do...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

correction - note last input to for shouldn't have the appltmp there.
What you describe is same thing skulker on AIX does in it's non-portable way.
mirdeAuthor Commented:
That worked just as i wanted it to, thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.