Get container ID from inside an OpenVZ container

The following snippet will get you the OpenVZ container, when you're in a container. I have added this to my zsh prompt, but this might be useful in other places, too.


# Get OpenVZ container ID (/proc/bc is only on the host):
if [[ -f /proc/user_beancounters && ! -d /proc/bc ]]; then
  CTID=$(sed -n 3p /proc/user_beancounters | cut -f1 -d: | tr -d '[:space:]')
By Daniel in Snippets2010-11-08 English (EU) Email


Comment from: Fueguito [Member] Email
aha .. kann ich damit daten aus dem openvz rausziehen oder was?
2010-11-09 @ 20:37
Comment from: ednong [Visitor]
ednongBekomm ich damit nun den Container oder dessen ID? Und was ist das ZSH?
2010-11-10 @ 23:42
Comment from: Daniel [Member] Email
Du bekommst damit die ID des Containers, in dem Du Dich gerade befindest ("virtueller Rechner").
ZSH ist eine Shell, so wie Bash, aber weitaus angenehmer.
2010-11-12 @ 18:10

Leave a comment

Your email address will not be revealed on this site.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
You can just use your OpenID to provide your name, e-mail and url.