{"id":583,"date":"2020-06-10T19:21:20","date_gmt":"2020-06-10T19:21:20","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=583"},"modified":"2020-06-10T19:21:20","modified_gmt":"2020-06-10T19:21:20","slug":"how-to-run-a-command-in-all-openvz-containers","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/how-to-run-a-command-in-all-openvz-containers.html","title":{"rendered":"How To Run a Command in All OpenVZ Containers"},"content":{"rendered":"\n<p>You can run single command in a container using the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vzctl exec 201 service httpd status<\/pre>\n\n\n\n<p>How to find out all the VZ containers:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vzlist -a<\/pre>\n\n\n\n<p>The other way? Yes, there is. VZ list is stored inside a file \/proc\/vz\/veinfo, and we can use it with the help of shell to run command in each VZ as following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for i in `cat \/proc\/vz\/veinfo | awk '{print $1}'|egrep -v '^0$'`; \\\ndo echo \"Container $i\"; vzctl exec $i &lt;your command goes here>; done<\/pre>\n\n\n\n<p>An example, can be the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for i in `cat \/proc\/vz\/veinfo | awk '{print $1}'|egrep -v '^0$'`; \\\ndo echo \"Container $i\"; vzctl exec $i service httpd status; done<\/pre>\n\n\n\n<p>This should show all the httpd status of the VZ. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can run single command in a container using the following: How to find out all the VZ containers: The other way? Yes, there is. VZ list is stored inside a file \/proc\/vz\/veinfo, and we can use it with the help of shell to run command in each VZ as following: An example, can be &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/how-to-run-a-command-in-all-openvz-containers.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How To Run a Command in All OpenVZ Containers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[144,180,12,424,423],"tags":[428,425,426,427],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/583"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":2,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":585,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/583\/revisions\/585"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}