shell习题-清理日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell习题-清理日志相关的知识,希望对你有一定的参考价值。

要求:两类机器一共300多台,写个脚本自动清理这两类机器里面的日志文件。在堡垒机批量发布,也要批量发布到crontab里面。

A类机器日志存放路径很统一,B类机器日志存放路径需要用*匹配(因为这个目录里除了日志外,还有其他文件,不能删除。匹配的时候可用*.log)

A类:/opt/cloud/log/   删除7天前的
B类: /opt/cloud/instances/  删除15天前的

要求写在一个脚本里面。不用考虑堡垒机上的操作,只需要写出shell脚本。




#!/bin/bash

dir1=/opt/cloud/instances/ 
dir2=/opt/cloud/log/

  if [ -d $dir1 ];then
      find $dir1 -type f -name "*.log" -mtime +15 |xargs rm -f
  elif [ -d $dir2 ];then
      find $dir2 -type f -mtime +7 |xargs rm -f
  fi


本文出自 “IT屌丝” 博客,请务必保留此出处http://68686789.blog.51cto.com/10438688/1978863

以上是关于shell习题-清理日志的主要内容,如果未能解决你的问题,请参考以下文章

Linux定时清理磁盘日志文件——Shell脚本

清理日志的shell

Shell实战定期清理日志文件的shell脚本

shell习题-处理日志

shell-清理日志

shell脚本自动清理服务器日志图片等信息