Remove out date logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove out date logs
# 1  
Old 10-09-2007
Remove out date logs

hi all,

i would like to write the shell script to remove the out-dated log
my log file name will be like this:
access_20050101.log
access_20050102.log
.
.
.
access_20071007.log
access_20071008.log
access_20071009.log

i has try to write the command as following, it will be remove the log if older then 90 days,
but if someone has modified the log, the file timestamp will be updated
so how can i remove the log base on the file name?

find /usr/local/apache2/logs -type f -mtime +90 -exec rm -f {} \;
# 2  
Old 10-09-2007
Ideally things like webserver logs shouldn't be updated manually. Also, if you are planning to make this a regular script, it will work fine with the find using +90. If you are looking to just do a one time cleanup, just manually remove files from, say, 2005 and 2006 using 'rm /usr/local/apache2/logs/access_2005*' and 'rm /usr/local/apache2/logs/access_2006*'
# 3  
Old 10-09-2007
blowtorch suggestion is better way...

If you really want to do that, you can try to get the yearmonth from the file and get current yearmonth to minus it, if result >= 4, then rm...

eg.
for file in `ll |grep access|awk '{print $9}'`;do
fdate=`echo $file | cut -c 8-13`;
cdate=`date +%Y%m`
dnum=`expr $cdate - $fdate`
if [ $dnum -ge 4 ]; then
rm $file
fi
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Solaris

How to print the particular date logs on UNIX (Solaris)?

I would like to get only some particular date logs from /var/adm/messages. Please suggest any command or script to get this. (3 Replies)
Discussion started by: seenuvasan1985
3 Replies

3. Shell Programming and Scripting

Grep a pattern in current date logs

Hello, I need to write one script which should search particular pattern like ABCD in log file name hello.txt only in current date logs. in current directory i have so many past date logs but grep should be applied on current date logs. on daily basis current date logs are in number 30 and... (2 Replies)
Discussion started by: ajju
2 Replies

4. UNIX for Dummies Questions & Answers

Removing the logs of previous date

Hi folks, Please advise there is directory named logs and which there are several logs are there with the name appended by date , I can take out the latest one through cd /var/log ls -ltr but please suggest the command through which I can remove the logs of all the previous dats , the... (2 Replies)
Discussion started by: SankalpS
2 Replies

5. Shell Programming and Scripting

How to remove the logs more than 5 days old

All, How to remove the logs that are more than 5 days old from a particular folder. Help will be highly appreciated. Regards Oracle User (2 Replies)
Discussion started by: Oracle_User
2 Replies

6. Shell Programming and Scripting

Lots of logs to move....don't remove if open

I have a ksh script that currently moves a day's worth of log files (about 15,000) files to a different directory. The issue is that about 100 of these files are still open for write when this happens. I need an efficient way to ensure that these files aren't open without doing an lsof on each... (7 Replies)
Discussion started by: nestafaria
7 Replies

7. Shell Programming and Scripting

How to find the password in the logs and remove the log which indicate it.

I want to crypt my files but as you know I have to write the password in the xterm...as you know there is a log where every thing I write in the xterm are store on it..how can I get the logs and delete the record which indicate my password..or prevent the xterm from storing my password in the... (2 Replies)
Discussion started by: ahmad.diab
2 Replies

8. Shell Programming and Scripting

Get Data Between a specific Date Range from logs

I need to extract data from logs for a mentioned date range..Its quite urgent can anyone help me out with it..its to be written in unix..just thought its better to specify.. (4 Replies)
Discussion started by: sankasu
4 Replies

9. Shell Programming and Scripting

not able to redirect the logs of a singl date in one system

Hi All, I have around 15 servers. I need to check for the error in /var/adm/messages in 15 servers of current date everyday and log it in one server. rsh is configured in all servers. The command I am using to accomplish this in shell script is rsh <remote sever> grep 'Jun 17'... (2 Replies)
Discussion started by: partha_bhunia
2 Replies

10. Solaris

Remove logs by date

Hi I Need To Remove Logs Older Than April 1 St(4/1/2007) By Date I Have A Script To Remove 3 Months Old Like Using 90 Days Thanks (3 Replies)
Discussion started by: cvdev
3 Replies
Login or Register to Ask a Question