Sript to delete older logs in a FS
Hi
I need some help with the scipt for deleting the older logs in a FS. I was using this below script previously where the FS was simple. find /var/sitelogs/httpd -mtime +1 -exec rm {} \; But now what we do normally with the current FS is : 1.cd /etc/httpd/application/ 2.du -sh * plication]# du -sh * 16K lost+found 302M ukwwwsit01 233M ukwwwsit04 1.7M ukwwwsit05 27M ukwwwsit05.working 152M ukwwwsit06 3.cd <dir which occupies more space> 4.Find older logs and delete. I am not sure how to go ahead with this as a script. Any suggestion would be appreciated. Thanks Madhu |
Well, the main problem is to find the name of the directory with the larger size. After that, you can use the same find command. To easily parse the output of du, first remove the -h option and try something like this (using command substitution):
Code:
large_dir=$(du -s * | sort -n | awk 'END{print $2}') Code:
find $large_dir -mtime +1 -exec echo rm {} \; |
Thanks for that.
So firstly i will use this below command to find the larger dir: large_dir=$(du -s * | sort -n | awk 'END{print $2}') [root@ngmlx494 application]# ll total 36 drwxr-x--- 2 apache apache 16384 Feb 10 2011 lost+found drwxr-xr-x 9 wwwsit01 apache 4096 Sep 14 2011 ukwwwsit01 drwxr-xr-x 9 wwwsit04 apache 4096 Jan 13 16:32 ukwwwsit04 drwxr-xr-x 8 wwwsit05 apache 4096 Sep 29 2011 ukwwwsit05 drwxr-xr-x 8 wwwsit05 apache 4096 May 8 2011 ukwwwsit05.working drwxr-xr-x 9 wwwsit06 apache 4096 Oct 14 2011 ukwwwsit06 [root@ngmlx494 application]# du -s * | sort -n | awk 'END{print $2}' ukwwwsit01 [root@ngmlx494 application]# Secondly i need to get in to Logs path (sorry i missed initially) cd logs Thridly use this find cmd to delete older logs: find $ logs -mtime +1 -exec echo rm {} \; Not sure how to link all the commands as a single script. |
Code:
#!/bin/bash |
All times are GMT -5. The time now is 11:10 PM. |