【发布时间】:2014-01-19 14:08:09
【问题描述】:
我最近编写了一个脚本,用于重新配置 Debian Stable (7.3) 系统上的所有软件包。我正在使用命令
dpkg-reconfigure -pcritical -a --force
一切正常,但今天我对代码进行了一些更改(我认为它们不相关),现在我收到了这个错误:
Can't exec "dpkg-query": Not a directory at /usr/sbin/dpkg-reconfigure line 98.
Can't exec "dpkg": Not a directory at /usr/sbin/dpkg-reconfigure line 82.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 83.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 84.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 85.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 86.
Can't exec "dpkg-query": Not a directory at /usr/sbin/dpkg-reconfigure line 98.
Can't exec "dpkg": Not a directory at /usr/sbin/dpkg-reconfigure line 82.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 83.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 84.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 85.
Use of uninitialized value $_ in pattern match (m//) at /usr/sbin/dpkg-reconfigure line 86.
Can't exec "dpkg-query": Not a directory at /usr/sbin/dpkg-reconfigure line 98.
Can't exec "dpkg-query": Not a directory at /usr/sbin/dpkg-reconfigure line 202.
readline() on closed filehandle QUERY at /usr/sbin/dpkg-reconfigure line 204.
有数千行类似的行(这些是最后一行)。 系统运行在运行级别 1 - 单用户 - 并以用户 root 身份运行。还有一个有趣的地方是 dpkg 退出码还是 0。
提前感谢您的帮助。
编辑:这是脚本
#!/bin/bash
DPKG_RECONFIG_PATH=/usr/sbin/dpkg-reconfigure
# Function for checking critical executables (exits on error)
chk_crit ()
{
TARGET=$1
PATH=$2
if [ -e $PATH ] # Pass 1 - checking existence
then printf "$TARGET exists\n"
else
printf "$TARGET doesn't exist!\n"
exit
fi
if [ -x $PATH ] # Pass 2 - checking execution permissions
then
printf "$TARGET is executable\n"
else
printf "$TARGET is not executable, attempting chmod!\n"
chmod 755 $TARGET_PATH
CHMOD_EXIT=$?
if [ $CHMOD_EXIT = 0 ] # Checking if chmod has succeeded
then
printf "chmod succeeded\n"
else
printf "chmod failed, $TARGET is unusable!\n"
exit
fi
fi
}
chk_crit dpkg-reconfigure $DPKG_RECONFIG_PATH
# Reconfiguring all packages, only asking critical questions
$DPKG_RECONFIG_PATH -pcritical -a --force
DPKG_EXIT=$?
if [ $DPKG_EXIT = 0 ]
then printf "Reconfiguration succeeded\n"
else printf "Reconfiguration failed\n"
exit $DPKG_EXIT
fi
exit
【问题讨论】:
-
看起来一些不相关的更改破坏了一些相关的系统组件。您是否手动更改了权限或删除了某些内容?
-
我的脚本中有一个函数在 dpkg-reconfigure 上运行 chmod 755 以防它无法执行,但日志文件告诉它没有做任何事情,dpkg 以可用的格式被发现。另外,当我手动运行 dpkg-reconfigure 时,它会成功。
-
我也不认为这有关系,但这不是一个好主意。如果
dpkg没有正确安装,您应该重新安装它,而不是尝试手动修复个别症状。假设您当前的问题是由一些类似的“保护措施”引起的,这可能也是合理的。 -
如果您重置系统变量
PATH,这就是失败的原因。这是 shell 用来查找命令的保留变量。 -
哦,我怎么会这么笨...现在我明白了,谢谢你的帮助!