Back to Blog
Disk Usage Script Linux: Simple Monitoring That Actually Works

Disk Usage Script Linux: Simple Monitoring That Actually Works

   Mariusz Antonik    Server Health    3 min read    5 views

Disk Usage Script Linux: Simple Monitoring That Actually Works

Disk space issues rarely happen suddenly. In most Linux environments, storage fills up gradually—logs grow, backups accumulate, and temporary files quietly expand. Without visibility, teams often discover the problem only when applications start failing or databases stop writing.

This is where a practical disk usage script linux approach becomes valuable. Instead of relying on heavy monitoring tools, a lightweight script gives you consistent visibility into how disk usage changes over time.

Why Disk Usage Monitoring Matters

Disk-related outages are among the most preventable infrastructure issues. Yet they still happen because teams lack simple, consistent reporting.

Common problems include:

  • Log files growing unexpectedly
  • Backup directories consuming more space than planned
  • Database storage expanding without visibility
  • Temporary files never being cleaned up

Using a bash script disk monitoring approach allows you to track these trends early—before they turn into incidents.

A Practical Disk Usage Script

Let’s start with a simple script that checks disk usage and logs it for analysis.

#!/bin/bash

DATE=$(date +"%Y-%m-%d %H:%M:%S")
OUTPUT=$(df -h / | awk 'NR==2 {print $5}')

LOGFILE="/var/log/disk_usage.log"

# Write output
echo "$DATE - Disk Usage: $OUTPUT" >> $LOGFILE

# Alert if above threshold
THRESHOLD=80
USAGE=$(echo $OUTPUT | tr -d '%')

if [ "$USAGE" -ge "$THRESHOLD" ]; then
    echo "Warning: Disk usage is above $THRESHOLD% ($OUTPUT)"
fi

This simple check disk usage linux script does three important things:

  • Captures current disk usage
  • Logs it with a timestamp
  • Triggers a basic alert when thresholds are exceeded

Automating with Cron

To make this useful, you need consistent execution. This is where cron disk monitoring linux becomes essential.

Add this to your crontab:

*/15 * * * * /path/to/disk_check.sh

This runs the script every 15 minutes, building a continuous record of disk usage.

Going Beyond Single Snapshots

Most teams rely on commands like df -h as a quick linux disk monitoring command. While useful, it only shows the current state—not how usage evolves.

By logging results over time, your script transforms into a trend-based monitoring tool. Instead of asking "Is disk full right now?" you start asking:

  • How fast is disk growing?
  • Which systems are trending toward capacity issues?
  • When will we actually run out of space?

Real-World Example

Consider a MySQL server where disk usage increases by 2–3% per day due to binary logs and growing datasets. A single snapshot might look safe at 60% usage.

But with a simple script logging data every 15 minutes, patterns become clear:

  • Weekly growth trends emerge
  • Unexpected spikes stand out immediately
  • Capacity planning becomes predictable

This is especially important for small teams that don’t have time to constantly check systems manually.

Extending the Script

Once the basics are working, you can expand your script to:

  • Monitor multiple mount points
  • Send alerts via email or Slack
  • Track top directories using du
  • Integrate with reporting dashboards

The goal isn’t complexity—it’s consistency and visibility.

Summary

A well-designed disk usage script linux setup doesn’t need to be complicated. With a few lines of Bash and a cron job, you can move from reactive firefighting to proactive capacity awareness.

Over time, these small data points build a clear picture of infrastructure health—helping you catch slow-growing issues long before they become outages.

If you want to take this further, structured reporting can turn raw disk data into meaningful insights across your environment. Solutions like Infrastructure Health Reporting help teams visualize trends across Linux and MySQL systems without adding unnecessary complexity.

About the Author
Mariusz Antonik

Oracle Cloud Infrastructure expert and consultant specializing in database management and automation.

All Tags
#Advanced #Bash #bash monitoring #bash scripting #Beginner #Best Practices #Capacity Planning #CPU Monitoring #cpu trends #cron jobs #database monitoring #database performance #detect slow queries mysql #disk capacity planning server #disk forecasting linux #Disk Monitoring #disk usage #disk usage script linux #disk usage trends #Early Detection #easy infrastructure monitoring #free-tier #Guide #Health Reporting #historical server monitoring #infrastructure health #infrastructure health reporting #infrastructure monitoring #infrastructure monitoring report #infrastructure trends monitoring #lightweight monitoring #linux cpu usage #linux disk capacity planning #linux disk usage #Linux monitoring #linux performance #linux server #linux server monitoring #linux servers #linux tools #low maintenance monitoring #monitor server trends #MySQL #mysql health reporting #MySQL monitoring #MySQL Performance #mysql performance monitoring #mysql query performance issues #mysql server monitoring #mysql slow query analysis #mysql slow query monitoring #mysql trends #networking #OCI #oracle-cloud #Performance Degradation #performance monitoring #performance trend monitoring #plan disk growth server #practical server monitoring #predict disk usage growth #query optimization #Security #server health #server health reporting #server health weekly report #server monitoring #server trend analysis #server-trends #simple monitoring system #simple ops monitoring #slow query reporting mysql #small business infrastructure #small infrastructure monitoring #small server monitoring #storage capacity planning linux #storage monitoring #subnets #system health reporting #Trend Monitoring #Tutorial #vcn