Re: Can somebody convert this short Perl Script to PHP?

From: Date: Tue, 30 Dec 2003 03:15:37 +0000
Subject: Re: Can somebody convert this short Perl Script to PHP?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-173464@lists.php.net to get a copy of this message
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> 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

« previous php.general (#173464) next »