The website log is regularly cleaned and backed up every day, and the log script is retained for 10 days
The website log is regularly cleaned and kept for 10 days. The daily log is backed up in an independent folder, and only 10 days of log records are kept. The log records over 10 days are automatically deleted. The following code is saved as log.sh. The pagoda scheduled task can be visited once a day at 0:00. The 10 days in the code can change the number of days you want to keep, #!/bin/bash # echo "/www/wwwlogs&q
#!/bin/bash #echo "/www/wwwlogs" #0 0 * * * /www/log.sh >/dev/null 2>&1 Dir=/www/wwwlogs time=`date +%Y%m%d%H%M%S` mkdir -p $Dir/${time}/ mv $Dir/*.log $Dir/${time}/ time=`date +%Y%m%d%H%M%S -d "10 day ago"` for subdir in `ls $Dir`; do if [ "${subdir}" \< "${time}" ]; then rm -rf $Dir/$subdir >/dev/null fi done