openvz scripts

By | 4 November 2013

In this article, we’ve put some small scripts that useful for openvz

vzstartall.sh
#!/bin/bash
## vzstartall - starts all openvz containers that are currently stopped
for arg in `vzlist -HS -o ctid`
do
echo working on container $arg
sudo vzctl start $arg
done

vzstopall.sh
#!/bin/bash
## vzstopall - stops all running openvz containers
echo stopping all running openvz containers
for arg in `vzlist -H -o ctid`
do
echo working on container $arg
sudo vzctl stop $arg
done


vzrestartall.sh
#!/bin/bash
## vzrestartall - restarts all openvz containers that are running
for arg in `vzlist -H -o ctid`
do
echo working on container $arg
sudo vzctl stop $arg
sudo vzctl start $arg
done

vzdiskspace.sh
#!/bin/bash
(echo "Hostname SpaceAllocated SpaceUsed SpaceRemaining Percent Filesystem"
for arg in `sudo vzlist -H -o ctid`
do
hostname=`sudo vzlist -H -o ctid,hostname | grep $arg | sed "s/$arg//g" - | sed 's/^[ \t]*//' - | sed 's/[ \t]*$//' -`
space=`sudo vzctl exec $arg df -h | grep /$ | sed 's/simfs//g' | sed 's/^[ \t]*//' - | sed 's/[ \t]*$//' -`
echo "$hostname $space"
done ) | column -t