1. Tools directory file structure [root@www tools]# tree tools/ tools/ ├── bin │ ├── del_history_files │ └── etc ├── del_history_files.cfg 2 directories, 2 files 2. Delete history file script del_history_files [root@www tools]# more tools/bin/del_history_files #!/bin/sh # Delete files in the specified directory whose file time is earlier than the specified time node. Time granularity: hours# Configuration file format: Directory to be cleaned = number of hours# # # define restricted path PATH="/bin:/usr/bin:/sbin:/usr/sbin" # adirname - return absolute dirname of a given file adirname() { odir=`pwd`; cd `dirname $1`; pwd; cd "${odir}"; } # --------- # constants # --------- MYNAM=`basename "$0"` MYDIR=`adirname "$0"` MYCFG="${MYDIR}/../etc/${MYNAM}.cfg" MYTMP="${MYDIR}/../tmp" MYLCK="${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[@]} do APP_PATH=`echo ${PP} | awk -F'=' '{print $1}'` N=`echo ${PP} | awk -F'=' '{print $2}'` if [ -d ${APP_PATH} ] ; then T=`/bin/date --date "${N} hours ago" "+%Y%m%d%H%M"` TMP_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 -rf find ${APP_PATH} -type d -empty -print0 | xargs -0 -n 100 rm -rf &> /dev/null fi done rm -rf ${MYLCK} 3. Delete the configuration file del_history_files.cfg of the history file script [root@www tools]# more tools/etc/del_history_files.cfg #Directory to be cleaned = number of hours /home/logs/nginx=720 /home/logs/varnish=720 4. Run crontab [root@www tools]# more /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ #clear old logs 00 6 * * * root /home/tools/bin/del_history_files The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: React+axios implements github search user function (sample code)
>>: Summary of MySQL's commonly used concatenation statements
In the front-end and back-end separation developm...
Use MySQL proxies_priv (simulated role) to implem...
1. Preparation 1.1 Download and install VMware 15...
MGR (MySQL Group Replication) is a new feature ad...
Table of contents MySQL inner join, left join, ri...
Table of contents 1. Direct assignment 2. Shallow...
Table of contents 1. What is Docker Compose? 2. D...
Each of these 16 sites is worth reading carefully,...
View Docker Network docker network ls [root@maste...
Preface Recently, I have been busy dealing with s...
Table of contents 1. Arithmetic operators 2. Comp...
Problem: The partition where MySQL stores data fi...
Table of contents 1. Sub-route syntax 2. Examples...
Recently I need to change the version of MySQL da...
This article example shares the specific code of ...