Execute a command in all running OpenVZ Containers

If you wish to execute a command in all running Containers, you can use the following script:
[codesyntax lang="bash"]

for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i <command>; done

[/codesyntax]

where <command> is the command to be executed in all the running Containers. For example:

[codesyntax lang="bash"]
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \

do echo "Container $i"; vzctl exec $i uptime; done
[/codesyntax]

Container 1
2:26pm up 6 days, 1:28, 0 users, load average: 0.00, 0.00, 0.00
Container 101
2:26pm up 6 days, 1:39, 0 users, load average: 0.00, 0.00, 0.00

Source: http://download.swsoft.com/virtuozzo/virtuozzo4.0/docs/en/lin/VzLinuxUG/260.htm

Scrie si tu o vorbulita


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.