javascript和JQuery焦点图和代码特效大全
当前最流行的开源CMS网站系统大全
当前位置:主页 > 操作系统 > Linux/Unix >

linux通用清理SHELL脚本

来源:IT技术网编辑:一页书发布于:2013-06-29人围观Linux脚本shell

根据给定日志目录,删除时间 结合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

Linux,脚本,shell,相关的文章
有时间的话来看看IT界的突发事件