<?xml version="1.0" encoding="windows-1252"?>
<node id="1008432" title="Unlink works in windows, not in Linux?" created="2012-12-11 19:31:28" updated="2012-12-11 19:31:28">
<type id="115">
perlquestion</type>
<author id="1005958">
jagexCoder</author>
<data>
<field name="doctext">
Hi

I have a server that creates log files of with certain file names, I'm use regex to detect these filenames and based on them delete the logs that are older than 24 hours.

The script works great tested on Windows XP, however in Linux it does not work. The backup files are not deleted and the log does not mention any files were deleted. Also the $unlink does not display the warning message.

Here's the relevant part of the code:
&lt;code&gt;
until ($log_written != 0)
{
    print FILE "*** SCRIPT RUN ON: " . $dt . " ***\n";
    print FILE "Deleting backup files more than 1 day old:\n";
    
    foreach my $file (&lt;grm_backup-*_*_*_*_*_*_EST_*.bak&gt;) {   
        if ( -M $file &gt; 2 ) {
            #print "Deleting the log file more than 1 days old: " . $file;
            unlink $file or die "\nCould not delete the backup $file: $!";
            print FILE "Deleted -&gt; " . $file . "\n";
        }
    }
    
    foreach my $file2 (&lt;backup_db-*_*_*_*_*_*_EST_*.bak&gt;){   
        if ( -M $file2 &gt; 2 ) {
            #print "Deleting the log file more than 1 days old: " . $file2;
            unlink $file2 or die "\nCould not delete the backup $file2: $!";
            print FILE "Deleted -&gt; " . $file2 . "\n";
        }
    }
    print FILE "\n\n";
    print "Backups older than 1 day have been successfully deleted! See LOG file for more details.\n";
    $log_written = 1;
}
&lt;/code&gt;

All advice appreciated thanks

EDIT: I should mention that unlink works if I type in:
"unlink cmc_rules-Mon_Dec_12_12_31_01_EST_2012"
Just not via the script</field>
</data>
</node>
