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    108 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 #alerts #Bash #bash cpu monitoring script #bash monitoring #bash scripting #Beginner #Best Practices #block volume backup #Capacity Planning #cloud backup strategy #cpu bottleneck #CPU Monitoring #cpu monitoring linux #cpu monitoring script linux #cpu trends #cpu usage trends #cpu usage trends linux #create oracle db system in oci #cron cpu monitoring #cron cpu monitoring linux #cron jobs #database monitoring #database performance #detect slow queries mysql #devops #disk capacity planning server #disk forecasting linux #disk growth trend linux #Disk Monitoring #disk usage #disk usage script linux #disk usage trends #Early Detection #easy infrastructure monitoring #free-tier #Guide #health dashboards #Health Reporting #historical server monitoring #how to monitor cpu usage linux #infrastructure #infrastructure health #infrastructure health dashboard #infrastructure health reporting #infrastructure monitoring #infrastructure monitoring report #infrastructure trends #infrastructure trends monitoring #Infrastructure Visibility #lightweight linux monitoring #lightweight monitoring #linux #linux administration #linux cpu monitoring #linux cpu usage #linux disk capacity planning #linux disk usage #Linux monitoring #linux monitoring setup #linux monitoring tools #linux performance #linux performance monitoring #linux server #linux server monitoring #linux servers #linux storage #linux tools #low maintenance monitoring #monitor cpu usage over time linux #monitor linux server health #monitor server trends #monitor small production server #monitoring without complexity #MySQL #mysql health reporting #MySQL monitoring #mysql optimization #MySQL Performance #mysql performance degradation #mysql performance monitoring #mysql performance trends #mysql query performance issues #mysql server monitoring #mysql slow queries #mysql slow query analysis #mysql slow query monitoring #mysql trends #mysql-health #networking #nsg #OCI #oci backup #oci bastion tutorial #oci block volume #oci infrastructure as code #OCI monitoring #oci networking #oci oracle database private subnet setup #oci oracle database tutorial #oci security #oci setup guide #oci terraform tutorial #oci tutorial for beginners #oci vcn terraform #oci virtual machine db system guide #oracle base database service tutorial #oracle cloud bastion #oracle cloud free tier tutorial #oracle cloud infrastructure step by step #oracle cloud infrastructure tutorial #oracle cloud storage #oracle database on oci setup #oracle-cloud #Performance #Performance Degradation #performance monitoring #performance trend monitoring #performance trends #plan disk growth server #practical server monitoring #predict disk usage growth #private instance access #query optimization #Security #security lists #server health #server health reporting #server health weekly report #server monitoring #Server Performance #server trend analysis #server-trends #simple cpu monitoring linux #simple linux monitoring #simple monitoring small business #simple monitoring system #simple ops monitoring #slow queries #slow query reporting mysql #small business infrastructure #small business IT #small business servers #small infrastructure monitoring #small server monitoring #ssh bastion #storage capacity planning linux #storage monitoring #subnets #System Health #system health reporting #terraform oci compute #terraform oracle cloud infrastructure #Trend Monitoring #trend-analysis #trends #Tutorial #vcn