Unix HOWTOs and Tips Short unix command line administration tips and scripts


Execute identical commands in all running OpenVZ containers on a hardware host

Suppose, that you have to execute some identical commands on all your running OpenVZ containers. For example you may want to check their disk usage, or ban an IP on all of them, or force a restart of their webserver for some reason. Typing the same commands over and over again is tiresome, and error prone. Suppose also, that you do not have an automated system like Ansible already (which by the way, I highly recommend) ...

Do not worry, just follow these steps:

1) Save the following script as allvpses_do, somewhere on your PATH, and make it executable:



for i in `vzlist -o veid -H|  xargs`; do
   echo "============================  VPS: $i: CMD: $THECMD ===================================";
   echo "$THECMD" | vzctl exec $i - | grep --line-buffered -v 'Executing command:' | sed -e "s@^@VPS $i: @gm"

2) Run a test command like this:

allvpses_do uptime

... or, you can try:

allvpses_do 'iptables --list -nv|grep DROP'

3) Enjoy your puppet master powers :-)

Posted by Delyan Angelov

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment


No trackbacks yet.