Skip to content

Instantly share code, notes, and snippets.

@jjpeleato
Last active April 13, 2026 10:14
Show Gist options
  • Select an option

  • Save jjpeleato/99b8b098028b594b0b11f3e22973de60 to your computer and use it in GitHub Desktop.

Select an option

Save jjpeleato/99b8b098028b594b0b11f3e22973de60 to your computer and use it in GitHub Desktop.
Monitors and logs disk usage trends into a CSV file.
#!/bin/bash
#
# Monitors and logs disk usage trends into a CSV file.
# Output is converted from KB to GB for better readability.
#
# Ideal for tracking long-term storage growth in VPS environments.
#
LOG_FILE="$HOME/storage-logger.csv"
if [ ! -f $LOG_FILE ]; then
echo "Date,Total (GB),Used (GB),Available (GB),Percentage" > $LOG_FILE
fi
STATS=$(df -k / | tail -1 | awk '{printf "%.2f,%.2f,%.2f,%s", $2/1024/1024, $3/1024/1024, $4/1024/1024, $5}')
DATE=$(date '+%Y-%m-%d %H:%M')
echo "$DATE,$STATS" >> $LOG_FILE
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment