2019-05-16 20:32:51 -07:00
|
|
|
|
|
|
|
# Mike's Disk Usage Warn Thing
|
|
|
|
|
2024-02-25 18:51:08 -08:00
|
|
|
This is a simple script that will emit a warning to stderr when your disk usage surpasses a configured threshold.
|
|
|
|
Makes it easy to get emails fron crontab when your disk gets too full
|
2019-05-16 20:32:51 -07:00
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
* pyenv
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
* pipenv inside
|
2019-05-16 20:32:51 -07:00
|
|
|
|
|
|
|
* *logger* program, which should be on most distributions
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
1. Install [pyenv](https://github.com/pyenv/pyenv)
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
2. cd to this repo's directory and run `$ pyenv install` to get the correct version of python
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:58:46 -08:00
|
|
|
3. Install pipenv with `$ pip install --upgrade pip pipenv`
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
4. Initialize the pip environment with `$ pipenv install`
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
5. Create a yaml configuration file somewhere.
|
|
|
|
|
|
|
|
6. Create a crontab entry that will call this script with an argument "--config" followed by the path to your configuration file.
|
2019-05-16 20:32:51 -07:00
|
|
|
|
|
|
|
## Command Line Arguments
|
|
|
|
|
|
|
|
This script needs command line arguments to work. Primarily, it needs to know the location of at least one valid configuration file
|
|
|
|
|
|
|
|
### --config < path >
|
|
|
|
|
|
|
|
Specifies a path to a configuration file or directory. If a directory is specified, it will be scanned for configuration files.
|
|
|
|
|
|
|
|
### Example Call With Arguments
|
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
```shell
|
|
|
|
cd /path/to/this/repo && pipenv run python main.py --config "/my/config/path-1" --config "/my/config/path-2"
|
2019-05-16 20:32:51 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
## Example Crontab Entry
|
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
As mentioned, the easiest way to use this script is with crontabs.
|
|
|
|
By default, cron jobs will send you an email any time a script outputs to stdout or stderr.
|
|
|
|
Since this script will output lots of information to stdout,
|
|
|
|
and only output to stderr when a disk has become full,
|
|
|
|
it's useful to redirect stdout to /dev/null, like so:
|
2019-05-16 20:32:51 -07:00
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
```shell
|
|
|
|
cd /path/to/this/repo && pipenv run python main.py --config "/path/to/config" > /dev/null
|
2019-05-16 20:32:51 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
So, in order to run this script every 5 minutes, use something like the following:
|
|
|
|
|
2024-02-25 18:46:38 -08:00
|
|
|
```shell
|
|
|
|
*/5 * * * * cd /path/to/this/repo && pipenv run python main.py --config "/path/to/config" > /dev/null
|
2019-05-16 20:32:51 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
|