Skip to content

Instantly share code, notes, and snippets.

@lingxd
Created April 22, 2022 08:38
Show Gist options
  • Save lingxd/891d029afb90658d45cdd2bde351a94a to your computer and use it in GitHub Desktop.
Save lingxd/891d029afb90658d45cdd2bde351a94a to your computer and use it in GitHub Desktop.
Linux根据磁盘空间占用情况进行清空固定的日志
#!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