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

cd /hyperion/logs/essbase/app

Check to find all the Essbase Application logs

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

Deleting the logs file more than 30 days

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

cd /hyperion/logs/essbase/app
cat *.Demo.log*

current format

[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

Hello mate,

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?

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