Schlagworte: shell prompt
08.11.10

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.
Code:
# 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:]') | |
fi |