Difference between revisions of "ExecuteInAllVEs"
Line 4: | Line 4: | ||
#!/bin/bash | #!/bin/bash | ||
# vzexec -- execute a command on all VEs | # vzexec -- execute a command on all VEs | ||
− | |||
if [ "$1" == "" ]; then | if [ "$1" == "" ]; then | ||
echo "$0 -- Execute a command on all VEs" | echo "$0 -- Execute a command on all VEs" | ||
Line 14: | Line 13: | ||
exit | exit | ||
fi | fi | ||
− | for | + | for veid in `vzlist -Hoveid`; do |
− | + | echo "*** VE $veid" | |
− | |||
− | |||
− | echo "*** VE $veid | ||
vzctl exec $veid $@ | vzctl exec $veid $@ | ||
done | done | ||
</code> | </code> |
Revision as of 15:20, 6 January 2008
I found myself often faced with a need to run the same command in all VEs, e.g. apachectl restart to restart all webservers or dmesg | tail to see the latest news from everybody. This simple utility is just a loop around vzctl exec but I find it very handy.
#!/bin/bash
# vzexec -- execute a command on all VEs
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 veid in `vzlist -Hoveid`; do
echo "*** VE $veid"
vzctl exec $veid $@
done