Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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...
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
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
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
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
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..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.