[Webinar] Streamline your web hosting managementRegister Today


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

Posted on 2010-03-30
Medium Priority
Last Modified: 2013-12-21

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.
Question by:mirde
  • 2
  • 2
  • 2
LVL 62

Expert Comment

ID: 29144183

Author Comment

ID: 29144341
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.
LVL 13

Accepted Solution

Rowley earned 2000 total points
ID: 29169500
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...
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 13

Expert Comment

ID: 29169692
correction - note last input to for shouldn't have the appltmp there.
LVL 62

Expert Comment

ID: 29198655
What you describe is same thing skulker on AIX does in it's non-portable way.

Author Closing Comment

ID: 31709212
That worked just as i wanted it to, thanks.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

613 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