定时检查文件大小,如果超过则删除

crontab 添加定时任务

* * * * * bash /data/check_mysql_read_only_auto_clean_log.sh
check_mysql_read_only_auto_clean_log.sh脚本
#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
file_size=`ls -la /data/check_mysql_read_only.log | awk '{print $5}'`

# 如果文件大于30M,那么删除
if [ $file_size -ge 31457280 ]
then
    rm -rf /data/check_mysql_read_only.log
    printf "\n-----`date "+%Y-%m-%d %H:%M:%S"` check_mysql_read_only.log size $file_size 大于30M 删除此文件\n\n" >> /data/check_mysql_read_only.log
else
    printf "\n-----`date "+%Y-%m-%d %H:%M:%S"` check_mysql_read_only.log size $file_size 小于30M 不做处理\n\n" >> /data/check_mysql_read_only.log
fi

 效果

posted @ 2022-11-18 16:39  szcj~  阅读(96)  评论(0)    收藏  举报