我一直在使用一个非常旧的 Solaris 系统,并且无法添加更多模块以使我的生活更轻松,并且我正在使用许多使用各种命令行选项的脚本。
我正在做的大部分工作实际上是在工作,但我想出了一些我似乎无法解决的问题。
我正在使用“dd”命令从磁带中提取数据,并且需要捕获输出以确定我是否遇到任何磁带读取错误。
(“comment()”是我已经创建的子程序)
#!/usr/local/bin/perl
$| = 1; #disable output buffering
$tarfile = '/mnt/test/tmp/12345.tar';
@tapeinfo = `dd if=/dev/rmt/1cbn of=$tarfile`;
foreach(@tapeinfo){
#Check to ensure that we're not getting read errors
$result = index($_,'read: I/O error');
if ($result < 0){
#No read error, log result
comment($_);
} else {
# read error, terminate
comment("Terminating due to tape read error : $_");
last; #exit loop if error is found
}
}
#terminate with logging
当脚本运行时,我看到“输入 123+0 条记录,输出 123+0 条记录”被发布到终端屏幕,但我的循环中 @tapeinfo 似乎根本没有进行测试。我没有收到错误或信息记录。
我在这里错过了一些非常简单的东西吗?