Created
April 22, 2022 08:38
-
-
Save lingxd/891d029afb90658d45cdd2bde351a94a to your computer and use it in GitHub Desktop.
Linux根据磁盘空间占用情况进行清空固定的日志
This file contains hidden or 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 | |
disk_use=`df -h / | head -2 | tail -1 | awk -F" " '{print $5}' | awk -F% '{print $1}'` | |
if [ $disk_use -gt 80 ] | |
then | |
# Delete log files older than 3 days | |
find /home/hokori/logs/ -mtime +3 -type d -exec rm -rf {} \; | |
else | |
# Delete log files older than 7 days | |
find /home/hokori/logs/ -mtime +7 -type d -exec rm -rf {} \; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment