怎么制作网站logo,长沙网站设计公司怎么样,彩票网站的统计怎么做,网站侧导航Linux使用shell脚本定时删除历史日志文件,文件,小时,时间,目录,脚本Linux使用shell脚本定时删除历史日志文件易采站长站#xff0c;站长之家为您整理了Linux使用shell脚本定时删除历史日志文件的相关内容。1、tools目录文件结构[rootwww tools]# tree tools/tools/├── bin│…Linux使用shell脚本定时删除历史日志文件,文件,小时,时间,目录,脚本Linux使用shell脚本定时删除历史日志文件易采站长站站长之家为您整理了Linux使用shell脚本定时删除历史日志文件的相关内容。1、tools目录文件结构[rootwww tools]# tree tools/tools/├── bin│ ├── del_history_files│└── etc├── del_history_files.cfg2 directories, 2 files2、删除历史文件脚本 del_history_files[rootwww tools]# more tools/bin/del_history_files#!/bin/sh# 删除指定目录下文件时间早于指定时间节点的文件时间粒度小时# 配置文件格式 需清理的目录小时数### define restricted pathPATH/bin:/usr/bin:/sbin:/usr/sbin# adirname - return absolute dirname of given fileadirname() { odirpwd; cd dirname $1; pwd; cd ${odir}; }# ---------# constants# ---------MYNAMbasename $0MYDIRadirname $0MYCFG${MYDIR}/../etc/${MYNAM}.cfgMYTMP${MYDIR}/../tmpMYLCK${MYTMP}/${MYNAM}.lock# perform some locking (as good as it gets in a shell)[ -s ${MYLCK} ] kill -0 cat ${MYLCK} 2/dev/null die ${MYNAM}: already running!echo $$ ${MYLCK}PATHS(cat ${MYCFG})for PP in ${PATHS[]}doAPP_PATHecho ${PP} | awk -F {print $1}Necho ${PP} | awk -F {print $2}if [ -d ${APP_PATH} ] ; thenT/bin/date --date ${N} hours ago %Y%m%d%H%MTMP_FILE/tmp/echo ${PP} | md5sum | awk {print $1}touch -t ${T} ${TMP_FILE}find ${APP_PATH} ! -newer ${TMP_FILE} -type f -print0 | xargs -0 -n 100 rm -rffind ${APP_PATH} -type d -empty -print0 | xargs -0 -n 100 rm -rf /dev/nullfidonerm -rf ${MYLCK}3、删除历史文件脚本的配置文件 del_history_files.cfg[rootwww tools]# more tools/etc/del_history_files.cfg#需清理的目录小时数/home/logs/nginx720/home/logs/varnish7204、crontab 执行即可[rootwww tools]# more /etc/crontabSHELL/bin/bashPATH/sbin:/bin:/usr/sbin:/usr/binMAILTOrootHOME/#clear old logs00 6 * * * root /home/tools/bin/del_history_files以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持易采站长站。以上就是关于对Linux使用shell脚本定时删除历史日志文件的详细介绍。欢迎大家对Linux使用shell脚本定时删除历史日志文件内容提出宝贵意见