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:
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \ do echo "Container $i"; vzctl exec $i <command>; done
where <command> is the command to be executed in all the running Containers. For example:
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`; \ do echo "Container $i"; vzctl exec $i uptime; done
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