Cutting logs

# Full-service a / nginx logs cut Collection
follows the cutting tool is to use logrotate ** ** a log end

```
vim /etc/logrotate.conf/channelHandle
/game/publish/pm2/*.log
{
su root root
daily
missingok
copytruncate
notifempty
dateext
sharedscripts
postrotate
/opt/scripts/move_old_log.sh
endscript
}
```
```

mkdir -p /opt/scripts
vim /opt/scripts/move_old_log.sh
```
```

#!/bin/bash
datestamp=$(date +%Y%m%d)
logdir=/game/log/$datestamp
mkdir -p $logdir
mv /game/publish/pm2/*log-$datestamp $logdir
find /game/log -mindepth 1 -maxdepth 1 -mtime +60 \
-type d | xargs rm -rf
```
```

chmod +x /opt/scripts/move_old_log.sh

3-22 point of time following changes to
[root @ logstash Ash] # CAT / etc / anacrontab
# / etc / anacrontab: the Configuration File for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly

```

The following is a log cutting point ** ** Nginx
focus the postrotate
`` `
[the root Ash @ logstash] CAT # /etc/logrotate.d/nginx
/usr/local/nginx/logs/*.log
{
SU the root the root
Daily
missingok
copytruncate
notifempty
dateext
sharedscripts
the postrotate
/opt/scripts/move_old_log.sh
/ bin / CAT /usr/local/nginx/logs/nginx.pid the kill -USR1 `2> / dev / null` 2> / dev / null || to true
endscript
}
`` `
follows the same script content, are generating the current time, the output to a new directory as the old log file location
` ``
[root @ logstash Ash] # CAT /opt/scripts/move_old_log.sh
#! / bin / the bash
datestamp, and = $ (DATE the Y% m%% + D)
logdir = / tmp / $ datestamp, and
mkdir -p $ logdir
mv /usr/local/nginx/logs/*.log-$datestamp $logdir
find /tmp -mindepth 1 -maxdepth 1 -mtime +60 \
-type d | xargs rm -rf
```

Guess you like

Origin www.cnblogs.com/capable/p/12171213.html