Logfile rotation script.

I'm trying to find or create a Perl script that:
Checks for and creates these files:

notes
notes.1
notes.2
notes.3
notes.4

The first represents the current log file and the others are older versions. Each time the script runs it would check for the existence of notes.3 and, if it exists, move it to notes.4. Then is should check for notes.2 and move it to notes.3 and so on, until notes is moved to notes.1.

I've looked on the net already, but they're just too complex and try to do too much compared to my requirements.

Does anyone know of a script that does this, or do you have any code that could be adapted easily?

Thanks!

With awk:

ls notes* | 
awk -F"." 'NF>1{d=$2+1; system("echo "$0 " " $1 "."  d)}END{system("echo notes notes.1")}' 

Use nawk or /usr/xpg4/bin/awk on Solaris.

Cool thxz for that!

I was just fumbling around and am testing this code out now and seems to be working for what I need. Thxz anyways for your help will save it; since other ways are always helpful too, thxz.

#!/usr/bin/perl 
 
use strict; 
use warnings; 
 
use File::Copy; 
for my $i ( 3, 2, 1 ){ 
  if( -e "notes.$i" ){ 
    my $j = $i + 1; 
    move( "notes.$i", "notes.$j" ) or die "Could not move notes.$i to notes.$j: $!\n"; 
  } 
} 
if( -e "notes" ){ 
  move( "notes", "notes.1" ) or die "Could not move notes to notes.1 $!\n"; 
}

BTW, I forgot to mention that the echo command must be replaced with the mv command if the command works as expected.

Regards