Hi, Tuesday, December 30, 2003, 2:50:17 AM, you wrote: DM> Hi, I am trying to make a log rotator and found a great perl script to do it DM> but, would really like it in PHP (one less langauge to maintain).
DM> I know the system has "things" in place to do this but, I don't have access DM> to the system /etc/log/ folder or the system log rotation scripts. I figured DM> a simple php command line script would be a good alternative to maintain my DM> own logs. DM> Here's the perl script: DM> #!/usr/bin/perl DM> $LOGPATH='/Users/cv_admin/mylogs'; DM> DM> @LOGNAMES=('housekeeper_log_deleter.log','mysqlbackups_deleter.log','webbac DM> kups_deleter.log'); DM> $MAXCYCLE = 4; DM> chdir $LOGPATH; # Change to the log directory DM> foreach $filename (@LOGNAMES) { DM> for (my $s=$MAXCYCLE; $s >= 0; $s-- ) { DM> $oldname = $s ? "$filename.$s" : $filename; DM> $newname = join(".",$filename,$s+1); DM> rename $oldname,$newname if -e $oldname; DM> } DM> } DM> Don Myers Here is an untested version you can start with #!/usr/bin/php <? $LOGPATH='/Users/cv_admin/mylogs'; $LOGNAMES= array('housekeeper_log_deleter.log','mysqlbackups_deleter.log','webbackups_deleter.log'); $MAXCYCLE = 4; chdir($LOGPATH); # Change to the log directory foreach ($LOGNAMES as $filename ) { for ($s=$MAXCYCLE; $s >= 0; $s-- ) { $oldname = ($s > 0)? $filename.$s : $filename; $newname = $filename.($s+1); if(file_exists($oldname)){ rename($oldname,$newname); } } } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php