Skip to content

Instantly share code, notes, and snippets.

@tsuna
Created March 3, 2014 19:05
Show Gist options
  • Save tsuna/9332259 to your computer and use it in GitHub Desktop.
Save tsuna/9332259 to your computer and use it in GitHub Desktop.
Shell script to automatically clean TSD's cache directory from a cron job
#!/bin/bash
CACHE_DIR=/tmp/tsd
diskSpaceIsShort() {
df -h "$CACHE_DIR" \
| awk 'NR==2{pct=$5; sub(/%/, "", pct); if (pct < 90) exit 1; exit 0;}'
}
if diskSpaceIsShort; then
find "$CACHE_DIR" -type f -atime +7 | xargs --no-run-if-empty rm
if diskSpaceIsShort; then
rm -rf "$CACHE_DIR"/*
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment