Delete logs every 3 hours


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete logs every 3 hours
# 1  
Old 12-08-2007
Delete logs every 3 hours

Hi,

I want to setup a cronjob that will delete logs every 2 hours. I have script that delete logs per day. but logging is too big and i want to run a conjob that will delete every 2 hours.

this is my current command but it deletes on a per day basis.

find . -name "*.log[0-9]*" -o -name "*.log" -mtime +3 |xargs rm -fR {} \;
# 2  
Old 12-08-2007
One way of doing it would be to set up a cron job that calls a shell script every hour.

Within the shell script, use the date utility to return the hour_of_the_day in 24 hr format. Test if (hour_of_the_day % 2) is zero. If so execute the remainder of the script, otherwise exit.
# 3  
Old 12-09-2007
Seems like you be better off managing your logfiles by rolling over (or archiving) them.
If your logfiles are generated on mount /u01/logfiles (for example). You may want to consider moving them to /u09/arch/logfiles and consider compressing them after the move. Then perform the remove/delete on those compressed files on the second mount.

That ensures that you have a current copy available and an archive copy .

Just a thought. Smilie
Avoids you being caught out if you need the current logfiles and the delete step rolls around.

Cheers,
Cameron
# 4  
Old 12-09-2007
Otherwise you can use your existing find ....

01 0,2,4,6,8,10,12,14,16,18,20,22 find [requires a starting point] -name "*.log[0-9]*" -o -name "*.log" -mtime +3 |xargs rm -fR {} \; >> /var/adm/opslogs/dlt_logfiles.log

Hope that helps some. Smilie

Cheers,
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compress and delete the older logs

Hello Guys, Can you please help me with a script which zips the older log files(1-2 weeks) and delete them? I want to run the script manually instead of setting it up in a cron job. Appreciate your help. Regards, Kris (6 Replies)
Discussion started by: kriss.gv
6 Replies

2. Shell Programming and Scripting

Delete logs older than 60 days

i am using HP-UX OS...... delete logs older than 60 days find -mtime +60 | grep -i '.*log' | xargs rm -mtime is nt available in HP-UX, pls tell me other option ? (2 Replies)
Discussion started by: only4satish
2 Replies

3. Shell Programming and Scripting

To delete logs older than 30 days

I want to write a shell script that deletes all log files in a directory that are older than 30 days except for 3 files: I am using the following command: find /tmp/logs -name "*.log" -mtime +30 -exec rm -f {} \;But this command deletes all the log files. How can i modify this script that... (5 Replies)
Discussion started by: mmunir
5 Replies

4. Shell Programming and Scripting

Command to clear logs for every 6 hours in solaris

Hi Folks, I need to remove log files for six hours on Solaris. before i used to do for every 24 hours below is the code for 1 day older log files, now i tried using -mmin +360 but it says command not found. Can someone please help me out!!! part of the code: LOG_FILE=`find /home/Logdir... (1 Reply)
Discussion started by: Sendhil.Kumaran
1 Replies

5. Shell Programming and Scripting

Retrieve logs for previous 4 hours

Hi, I am in the process of configuring a script, and i intend it to retrieve logs for previous four hours, and then scan for predefined errors. I am kind of stuck on the log retrieval part where the script will run early morning like 1 AM or 2 AM, the command as posted below will give me... (4 Replies)
Discussion started by: john_prince
4 Replies

6. Shell Programming and Scripting

Retrieve logs for last 4 hours

Our log file looks like this: 2010-11-18 00:57:01,698 ERROR Shipment Error Log:Error Details - Account Id:3962, PO:2710015, Line:2, File:221112901, Version:V1, Desc:Order cannot not be shipped as there are no line items in New state 2010-11-18 14:59:39,960 ERROR... (11 Replies)
Discussion started by: Deepthz
11 Replies

7. UNIX for Dummies Questions & Answers

Delete last 10 days logs

Hi Can u please tell me how to delete last 10 days logs .. (9 Replies)
Discussion started by: pb18798
9 Replies

8. Shell Programming and Scripting

Delete old logs

Hello All, We have a directory where we have old archived logs. They are numbered <logfile>.log.1 till <logfile>.log.100 or more. I just want to keep 10 log files and delete others through the script. Please advise. Thanks, Chiru (4 Replies)
Discussion started by: chiru_h
4 Replies

9. Shell Programming and Scripting

I need to delete the content out of a number of logs

I'm just starting out in scripting (taking online classes) but I need to know how to clean out (delete) the content of a number of logs. All of the files end in 'trc'. Does anyone have a script or command (SED or AWK) I can use? Julie (4 Replies)
Discussion started by: Jbolin01
4 Replies

10. UNIX for Dummies Questions & Answers

delete files that are over 2 hours old

guys, I have a need for a script that will delete all files in a given directory that are over 2 hours old. I will set this up to run in cron. I'm having a little trouble coming up with the syntax that will identify these files. Is there a variation of the ls command that I can use to identify... (3 Replies)
Discussion started by: hedrict
3 Replies
Login or Register to Ask a Question