#!/usr/bin/perl -w use strict; die("usage: rotate_logs.pl \n") unless ( $ARGV[0] and $ARGV[0] =~ m/\w+/ ); my $baselog=$ARGV[0]; my $last=5; while ( $last > 1 ) { $last--; rename_logs($last, $last+1); } rename( "$baselog", "${baselog}_1" ) if -e $baselog; open FH, ">$baselog" or die("unable to open baselog for writing: $!\n"); print FH "[ LOG created ", scalar(localtime), " ]\n"; close (FH); sub rename_logs { my $x=shift; my $y=shift; if ( -e "${baselog}_$x" ) { rename("${baselog}_$x", "${baselog}_$y"); } }