Delete log files content older than 30 days and append the lastest date log file date


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete log files content older than 30 days and append the lastest date log file date
# 1  
Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs

I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs

This is my script
Code:
cd /hyperion/logs/essbase/app

Check to find all the Essbase Application logs

Code:
find . -name *.log -exec ls {} \;

Deleting the logs file more than 30 days
Code:
find . -name *.log -mtime +30 -type f -exec rm {} \;

But the Application logs file content which are older than 30 days not getting deleted and not appending the lastest date in the application log file
Code:
cd /hyperion/logs/essbase/app
cat *.Demo.log*

current format


Code:
[Thu Sep 13 16:00:13 2012]Local/Demo///1/Info(1002035)
Starting Essbase Server - Application [Demo]

[Thu Sep 13 16:00:14 2012]Local/Demo///1/Info(1200480)
Loaded and initialized JVM module

[Thu Sep 13 16:00:14 2012]Local/Demo///1/Info(1200445)
External [GLOBAL] function [@ESSBASEALERT] registered OK

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1024033)*Missing Database Config File *[/essbase/hyperion/products/Essbase/EssbaseServer/app/Demo/Demo/Demo.cfg]*, Query logging disabled

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1203135)*Starting the Data Mining Framework

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1203136)*Data Mining Framework successfully initialized.

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1200551)*Allocated TRIGMAXMEMSIZE: *[4096]* Bytes.

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1013205)*Received Command *[Get Database Volumes]

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1013205)*Received Command *[Set Database State]

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1019018)*Writing Parameters For Database *[Demo]

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1019018)*Writing Parameters For Database *[Demo]

Tue*Nov*27*19:09:52*2012*Local*Demo***1*Info*(1013205)*Received Command *[Get Database State]

I want to remove sep month data in log file and only need to have Nov months data in the log file
ie Oct 29 - Nov 29 dates appearing inside the log file.like i have 5 application log files.Please have a solutions for this

Moderator's Comments:
Mod Comment edit by bakunin: Please view this code tag video for how to use code tags when posting code and data.

Last edited by bakunin; 11-28-2012 at 04:08 PM..
# 2  
Hello mate,

Quote:
But the Application logs file content which are older than 30 days not getting deleted and not appending the lastest date in the application log file
Quote:
find . -name *.log -mtime +30 -type f -exec rm {} \;
this code finds .log files which are older than 30 days and deletes them but do not consider the contents of the files (time stamps) while deleting them but just the creation time of the file..

I didnt get what you needed exactly, do you need to check the time stamps of a log file (the last row especially) and check if its odler than 30 days? than if so delete it?
# 3  
Yes i want to check the time stamps generated inside the log file start date - till date and check if its older than 30 days delete the content of a log file and only to Oct 29 -Nov 29

---------- Post updated at 10:59 AM ---------- Previous update was at 10:51 AM ----------

only to Oct 29 -Nov 29 log file content should be present.Rest of the content inside the log file should be deleted
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #353
Difficulty: Medium
mawk is a very fast AWK implementation by Mike Brennan based on a Python interpreter.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Subscribers with Date 90 days older than current date

I have to display only those subscribers which are in "unconnected state" and the date is 90 days older than today's date. Below command is used for this purpose: cat vfsubscriber_20170817.csv | sed -e 's/^"//' -e '1d' | nawk -F '",' '{if ( (substr($11,2,4) == 2017) && ( substr($11,2,8) -lt... (1 Reply)
Discussion started by: dia
1 Replies

2. Shell Programming and Scripting

Append date to sql*plus spool (log) file in shell script

SQL*Plus version : 11.2.0.4 OS : Oracle Linux 6.5 SQL*Plus is a client application to connect to oracle database. The log file for this tool is generated via spool command as shown below. I am trying to append date ( $dateString ) to spool file as shown below. $ cat test2.sh #!/bin/bash... (4 Replies)
Discussion started by: kraljic
4 Replies

3. Shell Programming and Scripting

To nullify multiple log files older than X days.

Hi, I am writing the script for tomcat logs clean up ending with *.txt and *.log. cleanup should be applied to logs older than 7 days logs same will be scheduled in cron. after googling found below but it only help partially. find . -type f -name '*.log' -exec truncate --size 0 "{}" \; I... (6 Replies)
Discussion started by: Riverstone
6 Replies

4. Shell Programming and Scripting

List and Delete Files which are older than 7 days, but have white spaces in file name

I need to list and delete all files in current older which are olderthan 7 days. But my file names have white spaces. Before deleting I want to list all the files, so that I can verify.find . -type f -mtime +7 | xargs ls -l {} But the ls command is the working on the files which have white... (16 Replies)
Discussion started by: karumudi7
16 Replies

5. UNIX for Dummies Questions & Answers

How to delete all the files older than a date?

Hi, I need a command for deleting all the compress files *.Z that are older than the current date - 5 days. Basically I have a directory where daily I meet some back up files and I want to remove automatically the ones 5 days (or more) older than the current date. How can I write a 'rm' command... (1 Reply)
Discussion started by: Francy
1 Replies

6. UNIX for Dummies Questions & Answers

Find all log files under all file systems older than 2 days and zip them

Hi All, Problem Statement:Find all log files under all file systems older than 2 days and zip them. Find all zip files older than 3days and remove them. Also this has to be set under cron. I have a concerns here find . -mtime +2 -iname "*.log" -exec gzip {} Not sure if this will work as... (4 Replies)
Discussion started by: saurabh.mishra
4 Replies

7. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

8. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

9. Shell Programming and Scripting

Delete log file entries based on the Date/Timestamp within log file

If a log file is in the following format 28-Jul-10 ::: Log message 28-Jul-10 ::: Log message 29-Jul-10 ::: Log message 30-Jul-10 ::: Log message 31-Jul-10 ::: Log message 31-Jul-10 ::: Log message 1-Aug-10 ::: Log message 1-Aug-10 ::: Log message 2-Aug-10 ::: Log message 2-Aug-10 :::... (3 Replies)
Discussion started by: vikram3.r
3 Replies

10. Shell Programming and Scripting

Delete files older than 3 months.(read date from the name of the file)

Guys, My log files stored in the date format format below(log_20080714072942): TIMESTAMP=`date +%Y%m%d%H%M%S` LOG=/log/log_${TIMESTAMP}.log I'm looking for a shell script which deletes all files which is older than 3 months from today. Regards, Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies

Featured Tech Videos