Solved

move big log files

Posted on 2002-07-21
3
195 Views
Last Modified: 2010-03-05
I'm trying to write a perl script for my server to search for big(1.5GB) *.log files and move them to filename.log.1 and if such files exists to overwrite it.

So if a file error.log exists somewhere on my server and it reaches 1.5GB in size this script will move it to error.log.1 and file error.log would be gone or be empty.

I'm looking at seek() coomand but it can only search for files on specific file size how do i search for a *.log file of over 1.5GB?

If someone would write this complete script for me i'll give 200 points.
And only 100 points if you tell me what to use to accomplish this task.
0
Comment
Question by:petka
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 200 total points
ID: 7168418
use File::Find;
$start_dir = '/home';
# use standard File::Find module to traverse directory tree
&File::Find::find(\&wanted,$start_dir);

# define action sburoutine for file find
sub wanted
{
  $MAX_SIZE = 1024 * 1024 *1024 * 1.5;
  # File is greater than 1.5 GB in size and end in .log extension
  if ( -s $_ > $MAX_SIZE and $_ =~ /\.log$/ )
  {
     # move file to file.1 by renaming, original file name is gone
     unless ( rename($File::Find::name,"$File::Find::name\.1") )
     {
         die "Could not rename log file";
     }
  }
}

0
 

Author Comment

by:petka
ID: 7168543
The only answer given and such a perfect answer.
Thanks alot!
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 7168613
Glad to help. Only other you might need to consider is if the log file is still being updated by another process. In this case the rename would probably fail.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl efficient DB Call 8 81
perl CPAN issue 3 98
syslog unix file 20 68
add a syntax to a csv file 8 98
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now