LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-17-2009, 10:29 PM   #1
renuka
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
help in logrotation


Hi

I need help in rotating logs.
A folder /tftpboot holds following directories, these directories are created everyday automatically, these are backup folders, that is they hold backup of data.
drwxr-xr-x 2 phone phone 4096 Nov 1 13:19 1nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 2 13:19 2nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 3 13:19 3nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 4 13:19 4nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 5 13:19 5nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 6 13:19 6nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 7 13:19 6nov09.bkp
drwxr-xr-x 2 phone phone 4096 Nov 8 13:19 6nov09.bkp

I need to set up an entry in logrotate to delete these backup directories in /tftpboot directory that are greater than 1 week old.
Can someone help me how to do the same?
 
Old 11-17-2009, 10:59 PM   #2
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
If you want to delete , then i think logrotate command is not needed.

What you can do is write a shell script in a file and put that file in /etc/cron.daily folder

I mean create a shell script file
root#vi /etc/cron.daily/delolddir.sh
(and add following lines)
find /tftpboot -name "*.bkp" -type f -atime +7 exec {} \;


This script will delete you 7 week old *.bkp file at 4.02 am daily.

Thanks

Last edited by vishesh; 11-17-2009 at 11:00 PM.
 
Old 11-18-2009, 02:05 AM   #3
renuka
LQ Newbie
 
Registered: Nov 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi Vishesh,

Thank you for the reply and solution. I will be deleting the directories as you said.
 
Old 11-18-2009, 02:22 AM   #4
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
Just let me know by click on thumb if your job get done.

Thanks
 
Old 11-22-2009, 09:09 PM   #5
rashmeepawar
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
Hi Vishesh,

Here are the following things i did in cron and the script...

#vim /etc/cron.d/dailyvoicebkp
5 13 * * sun root /usr/sbin/voicebkp.sh

#/usr/sbin/voicebkp.sh
find /tftpboot -name '*.bkp' -type d -atime +7 -execdir /bin/rm -rf {} \;


the directories were not deleted.
I even executed the 'find' command from command promt but the directories were not deleted. Let me know if i am going wrong anywhere in above 2 files...

Thanks
-Rashmi
 
Old 11-22-2009, 09:36 PM   #6
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
Sorry
Following will now do you job

find /tftpboot -name '*.bkp' -atime +7 -type d -exec /bin/rm -rf {} \;
or you can try
find /tftpboot -name '*.bkp' -type d -atime +7 -print | xargs /bin/rm -rf


If this not working whats message it give? I checked it on my system and its working
Thanks

Last edited by vishesh; 11-22-2009 at 09:53 PM.
 
Old 11-22-2009, 10:00 PM   #7
rashmeepawar
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
hi vishesh,

These are the dirs in /tftpboot dir
drwxr-xr-x 2 phone phone 4096 Nov 10 13:19 mummss01_200911101304_aynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 11 03:20 mummss01_200911110305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 12 03:20 mummss01_200911120305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 16 12:32 mummss01_200911161216_aynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 17 03:20 mummss01_200911170305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 18 03:20 mummss01_200911180305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 19 03:20 mummss01_200911190305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 20 03:20 mummss01_200911200305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 21 03:20 mummss01_200911210305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 22 03:20 mummss01_200911220305_uynyy.bkp
drwxr-xr-x 2 phone phone 4096 Nov 23 03:20 mummss01_200911230305_uynyy.bkp


I executed the command as you said from commandline yet the directories were not deleted...directories created on 10 11 and 12th of Nov should be deleted but they dont get deleted
 
Old 11-22-2009, 10:17 PM   #8
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
See atime basically refer to access time , i think your directory are accessed within a week any how. So use
mtime parameter instead on atime. Remember what you see in ls -l is modified time not access time.
so try this
find /tftpboot -name '*.bkp' -mtime +7 -type d -exec /bin/rm -rf {} \;

and let me know,

To see last access time you can use stat command. For example stat dirpath

thanks
 
Old 11-22-2009, 10:52 PM   #9
rashmeepawar
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
hi vishesh

I executed the cmd as you said on cmd line using -mtime and it worked...the directories on 10th 11th and 12th nov were deleted..i would like to know one thing is that when i executed the find cmd
"find /tftpboot/ -name '*.bkp' -mtime +7 -type d -exec /bin/rm -rf {} \;
"
i got following error:

find: /tftpboot/mummss01_200911101304_aynyy.bkp: No such file or directory
find: /tftpboot/mummss01_200911120305_uynyy.bkp: No such file or directory
find: /tftpboot/mummss01_200911110305_uynyy.bkp: No such file or directory

why this thing happened?
 
Old 11-22-2009, 11:03 PM   #10
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
Ya may be you face this warning
But my 2nd command suggestion will not produce any warning
find /tftpboot -name '*.bkp' -mtime +7 -type d -print | xargs /bin/rm -rf

The reason of above warning is rm -rf unable to handle list of directories
 
Old 11-22-2009, 11:17 PM   #11
rashmeepawar
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
Hi vishesh,

Thank you very much for your help...its working now as expected...
One more thing i want to tell you is that i was not sure if logrotate works for directories as well or not...i tried using logrotate and it worked for directories..

Thanks
-Rashmi
 
  


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
setting logrotation for apache-1.3.35 dianarani Linux - Server 1 06-04-2007 03:27 AM
edited logrotation cyberpunx Linux - Software 0 09-06-2005 01:55 PM
logrotation doesn't working properly emailssent Linux - Networking 1 03-02-2005 10:54 AM
customizing Debian (deluser, logrotation, etc) markus1982 Linux - Distributions 0 05-25-2003 04:48 AM
logrotation cuss Linux - General 3 02-17-2003 01:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:51 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
Open Source Consulting | Domain Registration