Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run the following command across all OpenVZ containers to update/upgrade:

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

In all cases, I get the following error:

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

And when there are updates available, the prompt "Do you want to continue" is skipped. Also, dpkg cannot set a lock:

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?

How can I fix this?

share|improve this question
up vote 2 down vote accepted

Try this:

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

The && means "If the previous command completes successfully, continue to the next."


exec CTID command

Executes command in a container. Environment variables are not set inside the container. Signal handlers may differ from default settings. If command is -, commands are read from stdin.

exec2 CTID command

The same as exec, but return code is that of command.

On the other hand

enter CTID [--exec command [arg ...]]

Enters into a container (giving a container’s root shell).

Option --exec is used to run command with arguments after entering into container. This is useful if command to be run requires a terminal

share|improve this answer
Wow, now that was easy. Thanks! I added a "&& exit" to make it quit the VZ container to match the exec2 command. – mo. Sep 17 '13 at 23:35
Yes, the correct one is using "&&", sorry, it was a typo copied from the original question. Thanks for pointing out. – javix Apr 10 '14 at 22:19

Do not use this idiom "apt-get update & apt-get upgrade" as the upgrade will proceed simultaneously with the update which will cause the update to lock the database and the upgrade will fail.

One of the following will be correct:

vzctl enter $VM --exec "apt-get update && apt-get -y upgrade" [note: edited Javix's answer above]


vzctl enter $VM --exec "apt-get update; apt-get -y upgrade"

In the first command, the upgrade will proceed only if the update was successful. In the second, it will be attempted anyway.

For each, I've also added a -y for the upgrade to answer "yes" to any questions, which is useful for unattended upgrades such as this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.