当每日 Cron 运行 apt-show-versions 时会显示以下错误。
/etc/cron.daily/apt-show-versions:
Use of uninitialized value $value in substitution (s///) at /usr/bin/apt-show-versions line 586, <FILE> line 174.
Use of uninitialized value $value in substitution (s///) at /usr/bin/apt-show-versions line 587, <FILE> line 174.
Use of uninitialized value $value in substitution (s///) at /usr/bin/apt-show-versions line 586, <FILE> line 174.
Use of uninitialized value $value in substitution (s///) at /usr/bin/apt-show-versions line 587, <FILE> line 174.
以下是第 586 行附近的代码片段:
551 sub parse_file {
552 my ($file, $status) = @_;
553 my ($key, $value, $package, $packages);
554
555 my $release = &determine_pkgfile_release($file);
556 open FILE, $file or &die("Can't open file $file: $!\n");
557 if ($opts{'verbose'}) {print "Parsing $file...";};
558 while (<FILE>) {
559 if (/^$/){
560 unless (defined $package) {next};
561
562 if ($status) { # Are we parsing the status file?
563 # if we did not specify a package or pattern
564 # only include installed packages
565 unless ($mode == $MODE_ALL and
566 ($package->{$STATUS} =~ /not-installed|config-files/ or
567 # don't print holded packages if requested
568 ($opts{'nohold'} and $package->{$STATUS} =~ /hold/))) {
569 $packages->{$package->{$PACKAGE}}{$package->{$ARCH}} = $package;
570 }
571 }
572 else {
573 if (!defined $packages->{$package->{$PACKAGE}} or
574 !defined $packages->{$package->{$PACKAGE}}{$package->{$ARCH}}{$VERS} or
575 $vs->compare($packages->{$package->{$PACKAGE}}{$package->{$ARCH}}{$VERS},
576 $package->{$VERS}) < 0) {
577 $package->{$RELEASE} = $release;
578 $packages->{$package->{$PACKAGE}}{$package->{$ARCH}} = $package;
579 }
580 }
581 undef $package;
582 next;
583 }
584 unless ((/^Package/) || (/^Version/) || (/^Status/) || (/^Source/) || (/^Architecture/)) {next};
585 ($key, $value) = split /: /, $_;
586 $value =~ s/\n//;
587 $value =~ s/\s\(.*\)$//; # Remove any Version information in ()
588 $package->{$key} = $value;
589 }
590 if ($opts{'verbose'}) {print " completed.\n"};
591 close FILE;
592 return $packages, $release;
593 }
594
我搜索并找到了类似(但不同)的主题,其中的解决方案我不确定是否有效。提前感谢帮助。
/var/lib/dpkg/status
根据@meuh 的要求编辑代码
162 Description: Micro string library: shared library
163 ustr (Micro string library) is a string API for C. It has tiny overhead over
164 just plain strdup(), is much safer, is easier to use, is faster for many
165 operations, can be used with read-only or automatically allocated data. You
166 don't even need to link to the library to use it (so there are no
167 dependencies).
168 .
169 This package contains the shared library for ustr.
170 Homepage: http://www.and.org/ustr/
171 Original-Maintainer: Vaclav Ovsik <[email protected]>
172
173 Package: libpam-winbind
174 Status: install ok installed
175 Priority: optional
176 Section: net
177 Installed-Size: 204
178 Maintainer: Ubuntu Developers <[email protected]>
179 Architecture: amd64
180 Multi-Arch: same
答案1
在我的系统上,该命令正在读取文件/var/lib/dpkg/status
,其中第 174 行是意外的格式。
perl 脚本apt-show-versions
期望以关键字开头的行,如下例所示:
Package: x11vnc-data
Version: 0.9.13-1.1
Status: install ok installed
Source: x11vnc
Architecture: all
这些关键字:
后面都有,但是在错误行上情况并非如此,因此 perl 脚本指令:
($key, $value) = split /: /, $_;
将 $value 设置为未定义,因此下一条指令:
$value =~ s/\n//;
无法进行替换,并生成警告消息。我认为这不会破坏任何东西。这取决于关键字是什么。
查找/var/lib/dpkg/status
有问题的包的名称(行开头),Package:
并将其和错误行周围的几行添加到原始帖子中。
答案2
我遇到了同样的错误。
/usr/bin/apt-show-versions -iv
显示了它正在解析的文件。在出现错误后的文件中,我发现它包含:<tab>
而不是:<space>
。