1

这是我到目前为止所拥有的:

#!/usr/bin/perl

use strict;
use warnings;

use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error);
use File::Find;
use File::Basename;

my $directory = "/usr/www/op1/public/server";
my @list_of_files;

find sub {
        return if -d;
        my $current = basename("$File::Find::name");

        if ($current =~ /\.bz2$/i)
        {
                #print "<$current> is already compressed! Moving along!\n";
                return;
        }

        print "<$current> is being compressed!\n";
        bzip2 $File::Find::name => "$File::Find::name.bz2";

        if (!("$Bzip2Error" eq ""))
        {
                print "\n$Bzip2Error at $File::Find::name\n";
                print "Trying again to compress <$current>\n";
                bzip2 $File::Find::name => "$File::Find::name.bz2" or print "FAILURE 2!!!";
        }
}, "$directory";

基本上,如果它决定终止,则在进行 bzip 压缩时:

<bobsagot> is being compressed!
<arthur.bsp.bz2> is already compressed! Moving along!
<reed.bsp.bz2> is already compressed! Moving along!
<bobby.bsp.bz2> is already compressed! Moving along!
<bigjoe.bsp> is being compressed!
Terminated

它会立即从失败的地方拾取并继续前进,但是我没有打印出错误,$Bzip2Error所以我很茫然。如何捕获 bzip2 失败的事件?

谢谢!

4

2 回答 2

0

共享主机将 perl 执行时间限制为 60 秒。失去希望 :D

于 2013-04-29T12:07:33.727 回答
0

您是否在代码中犯了剪切粘贴错误?以“ system( ”开头的行不合适。

脚本是否在bzip2调用期间自行终止?

如果你写这样的代码会发生什么?

if ( ! bzip2 $File::Find::name => "$File::Find::name.bz2")
{
    print "\nBzip Errir is [$Bzip2Error] System Error is [$!] at $File::Find::name\n";
}
于 2013-04-16T13:04:44.407 回答