LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-23-2012, 03:29 AM   #1
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Rep: Reputation: Disabled
Delete cron script


Hello peoples

Hi just dropped by to ask if anyone can give me a sample script that can be executable in our daily cron.
The script should be able to delete all the folders from /temp (for example) that is 30 days older. This is for my disk maintenance so that it would have always a free space.
 
Old 03-23-2012, 03:37 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
This sounds like a homework question to me.

What have you tried yourself? What specifically has brought you unstuck?

We here at LQ don't just DO things for people, we are all about learning for yourself. Tell us what you have got so far, and where your problem is, and we will be happy to help you in the right direction.
 
Old 03-23-2012, 03:46 AM   #3
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 173Reputation: 173
well it's a good question, i could use that too.. (however just found out that my tmp uses as little as 155kb)
but it seems that it was already answered:here

Last edited by yooy; 03-23-2012 at 03:49 AM.
 
Old 03-23-2012, 04:54 AM   #4
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fukawi1 View Post
This sounds like a homework question to me.

What have you tried yourself? What specifically has brought you unstuck?

We here at LQ don't just DO things for people, we are all about learning for yourself. Tell us what you have got so far, and where your problem is, and we will be happy to help you in the right direction.
I've tried this one

55 14 * * * find /home/folders/ -ctime +30 -exec rm -rf {} \;

but the cron command deletes also the folders directory under /home/

actually the contents of /home/folders/ are bunch of auto generated folders every day.
 
Old 03-23-2012, 05:20 AM   #5
jack_9
LQ Newbie
 
Registered: May 2011
Posts: 23

Rep: Reputation: Disabled
Problem with find and rm ...
Use this one
rm -rf `find /home/folders/ -type d -ctime +30`

I would say, better NOT to use "rm" rather use "-delete" option of "find" command
 
1 members found this post helpful.
Old 03-28-2012, 06:48 AM   #6
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jack_9 View Post
Problem with find and rm ...
Use this one
rm -rf `find /home/folders/ -type d -ctime +30`

I would say, better NOT to use "rm" rather use "-delete" option of "find" command
Hello,

It still ended leaving the folders that is supposed to be deleted under /home/folders/

I would say I tried many options but majority output is, it deletes the folders directory under /home

is there any cron script that would delete the 30 days old folders including its subcontets

Last edited by apss_evaluator; 03-28-2012 at 06:55 AM.
 
Old 04-02-2012, 05:21 AM   #7
jack_9
LQ Newbie
 
Registered: May 2011
Posts: 23

Rep: Reputation: Disabled
Hey apss_evaluator,

Can you please paste the screen shot or give some examples
also give the output of "ls -ltr"
 
1 members found this post helpful.
Old 04-02-2012, 06:18 AM   #8
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jack_9 View Post
Hey apss_evaluator,

Can you please paste the screen shot or give some examples
also give the output of "ls -ltr"
These 2 examples are what I've tried:

#!/bin/bash
find /home/folder/ -type d -ctime +30 -daystart -exec rm -rf "{}" \;

#!/bin/bash
find /home/folder/ -ctime +30 -daystart -exec rm "{}" \;


sample


[root@mysvr root]# ls -ltr /home/folders/
total 28
-rw-r--r-- 1 root root 0 Mar 27 16:13 file
drwxr-xr-x 3 root root 4096 Mar 28 14:02 generated1
drwxr-xr-x 3 root root 4096 Mar 28 14:32 generated2
drwxr-xr-x 3 root root 4096 Mar 28 17:34 generated3
drwxr-xr-x 3 root root 4096 Mar 28 18:45 generated4
drwxr-xr-x 4 root root 4096 Mar 29 09:57 generated5
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron appears to be messed up (E: cron: subprocess post-installation script returned e bujutsukai Linux - Newbie 1 07-24-2008 04:39 AM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 09:09 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Cron FTP get and delete dreammold Linux - Newbie 6 12-31-2007 12:39 PM
Cron - Delete Files nigeledge Linux - Software 1 10-14-2004 11:36 PM


All times are GMT -5. The time now is 07:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration