这是我到目前为止所拥有的:
#!/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 失败的事件?
谢谢!