Bash Command to Check Container Disk Space in Proxmox/ OpenVZ

Bash Command to Check Container Disk Space in Proxmox/ OpenVZ

Get Social!

proxmox logo gradKeeping an eye on all of your containers disk space can be time consuming if done one by one. Luckily, the vzlist command gives us access to many of the data and counters associated with each container.

Running vzlist on it’s own will give a list of the currently running containers and a few extra columns of information such as IP address and hostname.

You might be thinking that the above command doesn’t show anything about containers which are currently turned off, or about disk space. You’d be right!

Adding the –all switch will include all containers, regardless of their running state.

To add the disk space information we add the –output switch followed by the column names we want to display. For disk space, the column name is helpfully named diskspace so the command will look like this:

We now see the disk space of all of our containers, but with a problem. We have no idea (although in this example we do because we only have one container) which container the disk space output is for. We need to add a few more columns to the –output switch such as ctid and hostname.  (see below for a complete list of output columns)

The last trick here is to add a sort using the –sort switch and the column name

Let’s put all that together, plus a spot of awk magic to get a nice disk full percentage that we can work with:


Complete list of vzlist column headings

You can get a complete list of vzlist column headings with the following command:


How to Kill a Process Based on Part of the Process Name

Category : How-to

Get Social!

This is a small, handy snippet to kill a Linux process based on matching a string from the ps command output.

For example, we may want to kill the mongodb process based on matching just the string mongo.

We would use the below command, consisting of ps and grep to get the process we would like to kill.

We need to change the grep slightly, to stop the actual grep command process that we just ran from returning. We can add [] around part of the matching string to stop the process from being matched exactly as it will be parsed as a pattern, and not a literal string.

It doesn’t matter where on the string you add the brackets, as long as they are there somewhere.

Using awk we can now filter the results line to only print out the pid of the mongodb process.

Finally, we need to wrap all of this with the kill statement to remove the process. Be careful here as this will immediately kill the process with no warning or confirmation. This is just an example, it’s never a good idea to forcefully kill the mongodb process!

And that’s it, the mongodb process is dead!

Visit our advertisers


Quick Poll

Do you use ZFS on Linux?

Visit our advertisers