BASH
Check Server Disk Space and Inode Usage
A bash script to display current disk space usage and inode usage for all mounted filesystems, critical for maintaining server health and preventing storage-related outages in web servers.
#!/bin/bash
echo "--- Disk Space Usage (Human-readable) ---"
df -h
echo "
--- Inode Usage (percentage) ---"
# df -i shows inode usage. We use awk to print only filesystem and percentage, then grep -v to remove header.
df -i | awk '{print $1, $5}' | grep -v Use%
echo "
Explanation:
- Disk Space Usage (df -h): Shows total, used, available disk space in human-readable format.
- Inode Usage (df -i): Shows the number of files and directories (inodes) used and available. High inode usage can cause issues even with free disk space."
How it works: This script provides essential insights into server storage health. It first displays disk space usage in a human-readable format (`df -h`), showing occupied, available, and capacity percentages for all mounted filesystems. Following this, it lists inode usage percentages (`df -i`), which indicates the number of files and directories. Monitoring both is crucial for preventing unforeseen server downtime, as a full inode table can prevent new file creation even if disk space is abundant.