← Back to blog

Published on 2024-11-05 07:13 by Manu Gallego

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

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/MGalego/disk-usage-monitor.git
    cd 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:

    chmod +x disk_usage_monitor.sh
    
  4. (Optional) Set up cron job:

    • You can set up a cron job to run the script daily. 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
      
    • Make sure to 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:

./disk_usage_monitor.sh / 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

View on GitHub

Disk Usage Monitor

Written by Manu Gallego

← Back to blog