shell 脚本定期处理如下:

cat  /home/backup/logs_delete.sh

#!/bin/bash


/bin/find /data/logs/nginx/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/nginx/
/bin/find /data/logs/uwsgi/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/uwsgi/
/bin/find /data/logs/uwsgi/statistics/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/uwsgi/statistics/

/bin/find /mnt/logs/nginx/ -name "*.log*" -mtime +30 -type f|xargs rm -rf
/bin/find /mnt/logs/uwsgi/ -name "*.log*" -mtime +30 -type f|xargs rm -rf
/bin/find /mnt/logs/uwsgi/statistics/ -name "*.log*" -mtime +30 -type f|xargs rm -rf

 

 

查看执行结果

tree  /mnt/logs/uwsgi/

/mnt/logs/uwsgi/
── access.log-20180507
── statistics
│   └── access.log-20180507


tree /mnt/logs/nginx/
/mnt/logs/nginx/
└── info_access_2018-05-07.log

 

写入定时任务,每天做日志处理

crontab -l

0 4 * * * /bin/bash /home/backup/logs_delete.sh

 

参考文章:https://unix.stackexchange.com/questions/83711/moving-files-with-find-xargs-target-is-not-a-directory

相关文章:

  • 2021-11-22
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-31
  • 2021-06-07
  • 2022-12-23
  • 2021-12-21
  • 2021-11-23
  • 2021-05-17
相关资源
相似解决方案