nginx 按天日志分割 for linux
Shell脚本代码:
#!/bin/bash
nginx_pid=/var/run/nginx.pid
nginx_log_dir=/data/logs/nginx
goaccess_dir=/opt/goaccess
#yyyy
year=`date -d "yesterday" +"%Y"`
#MM
month=`date -d "yesterday" +"%m"`
#yyyyMMdd
day=`date -d "yesterday" +"%Y%m%d"`
daycount=30
dayold=`date -d "$daycount day ago" +"%Y%m%d"`
nginx_log_old=$nginx_log_dir/access.log.$dayold
if [ -f "$nginx_log_old" ]; then
rm $nginx_log_old
fi
cd $nginx_log_dir
if [ ! -f "access.log.$day" ]; then
mv access.log access.log.$day
kill -USR1 `cat $nginx_pid`
fi
cd $goaccess_dir
mkdir -p html/$year/$month
bin/goaccess -f $nginx_log_dir/access.log.$day -d -a -p etc/goaccess.conf > html/$year/$month/$day.html
相关推荐
nginxs 2020-11-14
Guanjs0 2020-11-13
小木兮子 2020-11-11
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09
mqfcu 2020-11-10
windle 2020-10-29