💾 Archived View for logdog.flounder.online › bits › disk-usage-monitor.gmi captured on 2024-12-17 at 09:28:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Disk Usage Monitor

A simple Bash script that monitors disk usage on a specified directory and sends alerts via Telegram if usage exceeds a defined threshold. This script is useful for system administrators and developers who want to keep track of disk space usage and avoid running out of space unexpectedly.

Features

- Monitors the disk usage of a specified directory.

- Sends alerts to a Telegram bot when disk usage exceeds a specified threshold.

- Logs alert messages to a file for future reference.

- Lists the current percentage of disk usage and the top space-consuming files/directories.

Prerequisites

- A working Telegram bot (you can create one using BotFather at core.telegram.org/bots#botfather).

- Your bot's token and your chat ID to send messages.

- `curl` installed on your system to send HTTP requests.

Installation

1. Clone the repository:

clone https://github.com/MGalego/disk-usage-monitor.git

disk-usage-monitor

2. Edit the script:

- Open `disk_usage_monitor.sh` in your preferred text editor.

- Replace `<YOUR_BOT_TOKEN>` with your bot token.

- Replace `<YOUR_CHAT_ID>` with your chat ID.

3. Make the script executable:

+x disk_usage_monitor.sh

4. (Optional) Set up a cron job:

- Open the crontab editor:

```

crontab -e

```

- Add a line to run the script every day at 8:00 AM:

```

0 8 * * * /path/to/disk_usage_monitor.sh / 80

```

- Replace `/path/to/` with the actual path to your script and adjust the threshold as necessary.

Usage

To run the script manually, you can execute:

/ 80

- Replace `/` with the directory you want to monitor (default is the root directory).

- Replace `80` with your desired alert threshold percentage (default is 80%).

Log File

The script logs all alert messages to `disk_usage_log.txt` in the current directory.

License

This project is licensed under the MGPL-3.0 License. See the LICENSE file for details.

Acknowledgments

Telegram Bot API for the messaging capabilities.

Bash scripting for the implementation.

Inicio