在BASH中重新配置Dpkg

时间:2014-01-19 14:08:09

标签: bash debian dpkg

我最近做了一个脚本,重新配置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

1 个答案:

答案 0 :(得分:0)

嗯,对不起这个问题,因为这绝对是我的错误。感谢所有帮助我认识这个错误的人。

该脚本无效,因为我不小心使用$PATH作为我的一个自定义变量的名称。它重置了真实的$PATH并阻止了dpkg正确执行。现在我将其更正为$TARGET_PATH,一切正常。再一次,抱歉这么粗心。