crontab -l

*/1 * * * * /usr/bin/sh /data/scripts/remove_log.sh [root@VM__010_centos ~]# more /data/scripts/remove_log.sh #!/bin/bash echo "检查时间:" date dir=du -s /data/*|sort -nr | head -n 2|awk -F " " '{print $2}' disk_usage=df -h|grep /dev/vd|awk -F " " '{print $5}'|awk -F " " '{print $1}'|grep -oP '[0-9]*' echo "当前使用空间:" $disk_usage "%" if [ "$disk_usage" -gt "80" ];then echo "需要删除" find $dir -type f -mtime +90 -name *.txt|xargs rm -f #删除磁盘使用率前2的 else echo "不超过 80% 无需删除" fi