Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need simple script to rotate log files

Status
Not open for further replies.

lblauen

Technical User
Aug 13, 2002
69
0
0
I need a simple script to rotate some log files I have. They are as follows. I want to keep 30 days worth and lose the oldest. Or a setable # of days worth. They are made everyday.

reports.txt.012404
reports.txt.012504
reports.txt.012604
reports.txt.012704
reports.txt.012804
reports.txt.012904
reports.txt.013004
reports.txt.013104
reports.txt.020104
 
man find

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 


find /path/of/reports -mtime 1 -exec rm {} \;


--
| Mike Nixon
| Unix Admin
|
----------------------------
 
I think your mixed up vgersh99. I need script to rotate the reports and purge the oldest. I know how to find them. I'm not a programmer so I'm not sure how to make this happen. Like
mv report.txt report.txt.`date +%m%d%y` This is how they are made. I then want to move the reports.txt.012904 down a chain till # 32 gets removed.
I guess something like this??

mv reports.txt.?.31 reports.txt.?.32
mv reports.txt.?.30 reports.txt.?.31
etc ..
rm reports.txt.?.32
 
Mike,

I believe that should be:

find /path/of/reports -mtime +30 -exec rm {} \;

The command you posted will remove all files that were modified within the last 24 hours.

John
 
mtime won't work for this unless the date stamp is the same as the file date. If I copy the files to test this they all have the same date stamp. I need it to purge by file name.
example the report file is in /tmp/report directory and the file name is report.txt.012904 or report.txt.013004 the last part of the file name is made by the `date +%m%d%y` command.
 
When you create the log files, perhaps you could do...
[tt]
mv report.txt report.txt.`date +%d`
[/tt]
...then there is no need for any other rotation.
 
but will keep files from jan-30 till march,
... which shouldn't hurt.

If you think of playing around with find, you only need to copy the files with -p -flag, (preserver attribute: timestamp et. al.)

cp -p report* ~/test
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top