move big log files

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.
Who is Participating?
Kim RyanConnect With a Mentor IT ConsultantCommented:
use File::Find;
$start_dir = '/home';
# use standard File::Find module to traverse directory tree

# 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";

petkaAuthor Commented:
The only answer given and such a perfect answer.
Thanks alot!
Kim RyanIT ConsultantCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.