OpenVZ exec,无法重新打开stdin /无法lockingpipe理目录

我在所有OpenVZ容器上运行以下命令来更新/升级:

vzctl exec2 $VM "apt-get update & apt-get upgrade" 

在所有情况下,我得到以下错误:

 dpkg-preconfigure: unable to re-open stdin: No such file or directory 

当有可用的更新时,会跳过提示“您要继续”。 另外,dpkg不能设置locking:

 E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? 

我怎样才能解决这个问题?

尝试这个:

 vzctl enter $VM --exec "apt-get update && apt-get upgrade" 

&&表示“如果上一个命令成功完成,则继续下一个”。

http://wiki.openvz.org/Man/vzctl.8

exec CTID命令

在容器中执行命令。 环境variables不在容器内设置。 信号处理程序可能与默认设置不同。 如果命令是 – ,则从标准input读取命令。

exec2 CTID命令

与exec相同,但是返回码是命令的码。

另一方面

inputCTID [–exec命令[arg …]]

进入一个容器(给容器的根壳)。

选项–exec用于在进入容器后用参数运行命令。 如果要运行的命令需要terminal,这很有用

不要使用这个成语“apt-get update&apt-get upgrade”,因为升级将与更新同时进行,导致更新locking数据库,升级失败。

以下其中一个将是正确的:

vzctlinput$ VM –exec“apt-get update && apt-get -y upgrade”[注意:编辑过的Javix的回答]

要么

vzctlinput$ VM –exec“apt-get update; apt-get -y upgrade”

在第一个命令中,升级只有在更新成功时才会进行。 第二,无论如何都会尝试。

对于每个问题,我还添加了-y升级以回答“是”以解决任何问题,这对于无人参与的升级很有用。