Cleanup a log file data every 2 days

How do i cleanup a log file data every 2 days, I was using below command in a script to remove log file every 2 days, but looks like its not working as log file date and time gets updated every 5 mins. Is there a way ?

 find ./ \( -name . -o -prune \) -type f -mtime -2 -name /var/log/wpar_monitor_2days.log -exec rm -f {} \; 

So are you saying that some process is still writing to this 2 days old log file every 5 mins?

Yes, Its a log file for a monitoring cron job, which runs evey 5 mins and updates the log file time each time it updates, so the log file has current date and time.

I want to delete the data in this log file that is 2 days old, how do i do ?

I shall only guide you on one way of achieving the same..you can use this logic if you find it better than ones given by others here...

1>You can get the epoch seconds of the time of creation of the file using stat command

stat -c "%W"  file

2>Compare this with the epoch seconds of two days behind..if less than the epoch seconds of 2 days behind...go ahead and delete...
To calculate two days behind epoch seconds

$((`date +"%s"` - 172800))

msabhi@ giving error
# stat -c "%W" wpar_monitor_2days.log
ksh: stat: not found

Could you calculate the number of lines added to log file every day ?
Then you can use csplit to split the file and delete the the other one.

Well I assume, If file is continuously written after 5 mins duration then its updated time also current time only.
Better you provide some details about log files. At least log file date format.
From which we may get some clue to figure out how to achieve this.

Thanks:)

Suggestion: I think the best approach here is to re-write your script so that it will create a new log file every day and append to it (use date +"%Y%m%d" to name your file). This way you can use find command to find & delete logs that are more than 2 days old.

Can you try this

/usr/bin/stat -c "%W" wpar_monitor_2days.log

If this doesn't work, i guess stat is not available on your system...you can check the availability using

which stat

created log file with extension wpar_monitor_mail_txt.$$, And that way find and remove works...