Link to home
Start Free TrialLog in
Avatar of TakedaT
TakedaTFlag for United States of America

asked on

Need to schedule Linux script to remove directories and their contents

Hi,

I am looking for a script that I can schedule on a SuSE Linux Enterprise server that will run on a daily basis at 1am.  I need it to look in a certain directory for directories with folder named with the date of 90 days old or older and delete them along with their contents.

This is for a Squid box.  Every month or so, I go and delete daily logs that are older than 3 months.  Im looking to automate this.  Right now, I ssh into the box, and run the following command to remove all directories from the Month of February.

rm -rf /proxy/www/Daily/2013Feb*



If this was vbscript, it would take me a few minutes, but im not so good with linux scripting.  

If someone could also tell me how exactly to schedule the job, that would be great.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
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 TakedaT

ASKER

Thanks Arnold.  The command looks like it will work perfectly without the -exec part.  But I am having some trouble adding it to cron.  I logged in as root and typed 'vi crontab'.  Then I pasted your code in there and it never ran.  I have never used cron before, can you give me some more detail how to add it?
SOLUTION
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 TakedaT

ASKER

OK, got it.  I actually googled and found to use 'crontab -e' but the command swill wouldn't run.  Adding a space between the last } and the \ seems to have done the trick.

Thanks