美文网首页
Linux当文件大于100k自动备份,并清空

Linux当文件大于100k自动备份,并清空

作者: 王康健_0124 | 来源:发表于2019-04-15 10:25 被阅读0次
    #!/bin/bash
     for file in `ls /opt/lampp/logs/access_log`
     do
     if [ -f $file ]; then
     if [ `ls -l $file|awk '{print $5}'` -gt 10000 ]; then
     cp $file /tmp/
     >$file
     fi
     fi
     done
    

    添加到定时任务中,每天6点,12点,18点,24点执行
    crontab -e

    * 6,12,18,24 * * * sh bak.sh

    重启服务命令:[root@centos6 /]# service crond restart
    启动服务命令:[root@centos6 /]# service crond start
    停止服务命令:[root@centos6 /]# service crond stop

    相关文章

      网友评论

          本文标题:Linux当文件大于100k自动备份,并清空

          本文链接:https://www.haomeiwen.com/subject/uibuiqtx.html