Created
March 3, 2014 19:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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