I have a couple of clients who are on the same Verio/NTT Virtual Private Server (VPS) system, and I want to have some simple script to check their disk usage. It’s not a simple “du” sort of task, however, because of the peculiarities of the VPS environment. Any ideas?
Fortunately for you, VPS wizard Mark Sharkey of Precision Pros just recently published a great script that does just what you seek. Here’s his introduction to the script:
I needed an easy way to check my servers for users approaching their diskquota, so, I put together a simple script based off Scott Wiersdorf’s vlistuser. The script is called checkquota. It will display all users on the server that are using more than 80% of their disk quota. You can call this script with a cronjob so that an email is sent with a list of these users.
More information on the script can be found at Providertalk.com.
Here are the installation instructions:
You can find a copy of the source code: Checkquota.
Do this:
- Copy checkquota script to your server. You can do this by creating the file on your server and copy/paste the source code. Or, ftp the file. If you are ftp’ing the file, make sure you do it in ASCII.
- As root, save the file as /usr/local/sbin/checkquota and set permissions to 755.
- From an ssh command line, type ‘rehash’
- From an ssh command line, run checkquota -h to view available options.
Note that if you’re running bash or any other Bourne shell descendant you don’t need to worry about step #3 here.
When you run the script, here’s what you’ll see:
usage: checkquota [options]
options:
-a show all users
-h show help
-o show only users over quota (this is the default)
-t change threshold percentage (default is 80)
You may also use the following “long-style” options to achieve the
same effects as above:
–all show all users
–help show help
–over show only users over quota (this is the default)
–threshold change the threshold percentage (default is 80)
Very nice job, and a great script to study if you want to learn more about shell script programming. Of course, you might also like to check out my book Wicked Cool Shell Scripts, but that’s another story entirely! 🙂