返回顶部

收藏

linux通用清理脚本

更多

根据给定日志目录,删除时间 结合crontab进行清理日志,清理完成后,后在/var/log/deltelog/ 生成按照月的清理日志

#!/bin/sh
###########################
#delete log
# in_day_num: like 1 2 is delete 2day ago logs 
# in_log_path like tomcat log home
###########################
in_log_path=${1}
in_day_num=${2}

tmp_delete_log=/var/log/deletelog/"`date +%Y%m`.log"

deleteLog()
{
 inner_num=${1}
 #find log 
 echo "[`date`]  >> start delete logs---" >> $tmp_delete_log
 find ${in_log_path} -type f -mtime ${inner_num} -print0 | xargs -0 rm -rf
 echo "[`date`]  >> end delete logs---" >> $tmp_delete_log

}
init()
{
 mkdir -p /var/log/deletelog/
}
main()
{
 init
 if [ -z ${in_log_path} ];then
    echo "[`date`] >> error log_path not init---" >> $tmp_delete_log
  return
 fi

 inner_day_num=+7
 if [[ -n ${in_day_num} ]] && [[ ${in_day_num} -ge 1 ]] ; then
    inner_day_num=${in_day_num}
 fi
 deleteLog ${inner_day_num}
}

main
#该片段来自于http://outofmemory.cn

标签:shell,系统

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-04-24 09:42:19自定义配置网络ip、网关、dns by 玖夏
  2. 2014-04-25 20:37:29批量杀进程 by xfk
  3. 2014-04-27 12:35:26关闭IDE通道检测 by 好剑
  4. 2014-05-13 20:25:25更改电源管理方式 by owensh
  5. 2014-09-11 10:25:51Linux 定期备份脚本 by 凤歌
  6. 2014-09-20 19:52:36删除ssh中旧的RSA key by zjbpku
  7. 2014-09-27 11:08:36如何在centos中给鼠标右键菜单添加“打开终端”的菜单项 by owensh
  8. 2014-12-03 11:52:40更改系统启动菜单的时间 by zjbpku
  9. 2014-03-12 21:31:34改变我的文档路径 by xfk
  10. 2014-05-02 11:17:36禁止保留文档记录 by 凤歌
  11. 2014-05-27 10:32:06查看进程使用的端口 by Echo

发表评论