Difference between revisions of "ExecuteInAllVEs"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
Line 1: Line 1:
 
<code>
 
<code>
#!/bin/bash
+
  #!/bin/bash
CONFDIR="/etc/vz/conf"
+
  CONFDIR="/etc/vz/conf"
if [ "$1" == "" ]; then
+
  if [ "$1" == "" ]; then
  echo "$0 -- Execute a command on all VEs"
+
    echo "$0 -- Execute a command on all VEs"
  echo ""
+
    echo ""
  echo "Example: vzexec service httpd restart"
+
    echo "Example: vzexec service httpd restart"
  echo ""
+
    echo ""
  echo "Note that variables are expanded in the host's shell, and use '' to prevent this."
+
    echo "Note that variables are expanded in the host's shell, and use '' to prevent this."
  echo "Example:  vzexec echo \$PWD    and  vzexec 'echo \$PWD'  are different."
+
    echo "Example:  vzexec echo \$PWD    and  vzexec 'echo \$PWD'  are different."
  exit
+
    exit
fi
+
  fi
for veconf in $CONFDIR/*.conf ; do
+
  for veconf in $CONFDIR/*.conf ; do
  veid=`basename $veconf .conf`
+
    veid=`basename $veconf .conf`
  if [ "$veid" == "0" ]; then continue; fi
+
    if [ "$veid" == "0" ]; then continue; fi
  vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@"@@g'`
+
    vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@"@@g'`
  echo "*** VE $veid ($vename)"
+
    echo "*** VE $veid ($vename)"
  vzctl exec $veid $@
+
    vzctl exec $veid $@
done
+
  done
 
</code>
 
</code>

Revision as of 18:44, 3 January 2008

 #!/bin/bash
 CONFDIR="/etc/vz/conf"
 if [ "$1" == "" ]; then
   echo "$0 -- Execute a command on all VEs"
   echo ""
   echo "Example: vzexec service httpd restart"
   echo ""
   echo "Note that variables are expanded in the host's shell, and use  to prevent this."
   echo "Example:   vzexec echo \$PWD    and   vzexec 'echo \$PWD'   are different."
   exit
 fi
 for veconf in $CONFDIR/*.conf ; do
   veid=`basename $veconf .conf`
   if [ "$veid" == "0" ]; then continue; fi
   vename=`grep ^NAME $veconf | head -1 | sed -e 's@NAME=@@' | sed -e 's@"@@g'`
   echo "*** VE $veid ($vename)"
   vzctl exec $veid $@
 done