Maintain 30 days data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Maintain 30 days data
# 1  
Old 12-09-2002
Maintain 30 days data

Hi Folks,

I have a log file that keeps the information pn the date and time a specific transaction is firedup. I found that the log file keeps growing and I intend to limit the entry to the log file to 30 days.

Log file name is transaction.log, here is the content:

120802_23:47:37 abbbbccccc
120802_23:52:23 accccddddd
120802_23:57:23 adddeeeee
120902_00:01:03 abbbbbccccc
120902_00:02:28 accccddddeee
120902_00:02:37 eeeeddddddbbb
120902_00:02:48 eeeddbbbb
120902_00:02:57 aaaaeee

The first column represent the execution date and time, while the right column indicate ths transaction name. Using the date, how can I limit the data in the transaction.log to 30 rolling days.


Thanks,

Odogbolu98
Smilie
# 2  
Old 12-10-2002
I would do something like:
Code:
cp transaction.log transaction.log$(date "+%Y%m%d")
> transaction.log
find . -name transaction.log\* -mtime +30 -exec rm {} \;

once a day via a cron job that runs during the last minute of the day.
# 3  
Old 12-13-2002
Thanks Perderabo, I'll give that a trial.

-odogbolu98
# 4  
Old 12-14-2002
You saying, you want to clear out the log file,after 30 days.

Well heres a perl script i wrote to clear out a log file.if ur anygood at perl ( unlike me ) you can adapt it or use cron to run it.

code below :

#util to clear log file
#version 1.0
#-colinok

#usr/bin/perl

#open file
open (LOG, "> ENTER PATH TO FILE HERE ")
$log = LOG;

#clear file
print clear $log;

#close file
close (LOG);


hope this helps

- PERLEO
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Collect last 2 days data from /var/log/messages

I need to collect last 2 days data from /var/log/messages into a separate file (file format: flmessagetimedaymonth). I have collect today's month, date, time information in separate variable. Please help me in this issue (Probably need awk and grep function). month=$(date|awk '{print $2}')... (4 Replies)
Discussion started by: makauser
4 Replies

2. Shell Programming and Scripting

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... (9 Replies)
Discussion started by: aix_admin_007
9 Replies

3. UNIX for Dummies Questions & Answers

Script that will Delete and Maintain Files

Hi guys, Good day to all and Happy New Year!!! Cheers!!! I hope anyone could help/suggest me on hot to create a script that will monitor the directory where files are being dumped. I have a script in CRON that runs everyday and collect for logs with a filename of Output_$(date... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

4. Shell Programming and Scripting

maintain 32bit and 64bit C code

Hi, I have a C code which builds and works fine on 32bit linux machine. Now i want to convert that code to build and run on 64 bit linux machine. I dont want to maintain two separate sources for 32 and 64 bit build. Same source should get build on 32 as well as 64 bit machine (when a... (2 Replies)
Discussion started by: bhushan123
2 Replies

5. Shell Programming and Scripting

Log maintain in Perl

hi , While working on perl, have to write a continuous log file which I can monitor. I tried like, open (LOG,'>'.$log.'/Report_'.$todaysdate.'.log') or die("Unable to create the log file"); print LOG "\nDate : ".`date`; But when I ran the script in backend and monitor log, it... (1 Reply)
Discussion started by: Deei
1 Replies

6. UNIX for Dummies Questions & Answers

Just asking - Tips on how to maintain your scripts ..

Hi all, Just writing to ask if any one can advise on what tools to use best for maintaining your scripts ... preferably free/open source and portable if there is one, that is, one that can be placed and run on a USB stick ... At the moment, am having them in directories and files and no... (2 Replies)
Discussion started by: newbie_01
2 Replies

7. UNIX for Dummies Questions & Answers

maintain database script...

Hi there. i'm new user at here I need help for this. I need to write a script that maintains a database of cryptographic checksums. In other words, I need this script to check the files checksum whether the files has been modified or not. But i got no idea where to start. Hope anyone here can... (8 Replies)
Discussion started by: hihihehe
8 Replies

8. UNIX for Dummies Questions & Answers

How to maintain the content of array in any directory I go?

Hi all, I have this scenario where:- The file that I want to save its name into array df is my.08120323.trx which is located in the dir as below: $ pwd /u01/abc/def/SRC_datafiles $ ls *trx my.08120323.trx $ df=*"trx" ##keeping the filename... (1 Reply)
Discussion started by: luna_soleil
1 Replies

9. Shell Programming and Scripting

Add data in days:hours:min:sec format

I want to add these no. these are in the format of days:hours:minutes:sec I want result in this format only 0:00:04:59 0:00:00:12 0:00:00:28 0:00:00:03 0:01:29:35 0:00:00:19 0:01:05:21 Is any body ca help me????? To get This.. Thanks Nishant (1 Reply)
Discussion started by: krishna_sicsr
1 Replies

10. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question