nginx日志access.log error.log按天生成存储,定时删除日志
  BY1EvMhY1VNb 2023年11月02日 44 0
#!/bin/bash
#function:cut nginx log files for lnmp v0.5 and v0.6
#author: http://lnmp.org


#set the path to nginx log files
log_files_path="/data/nginxlog/"
log_files_dir=${log_files_path}
#set nginx log files you want to cut
log_files_name=(access )
#set the path to nginx.
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save
save_days=30


############################################
#Please do not modify the following script #
############################################
#mkdir -p $log_files_dir


log_files_num=${#log_files_name[@]}


#cut nginx log files
for((i=0;i<$log_files_num;i++));do
mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}${log_files_name[i]}.log_$(date -d "yesterday" +"%Y-%m-%d")
done


#delete 30 days ago nginx log files
find $log_files_path -mtime +$save_days -exec rm -rf {} \;

定时执行上面的脚本即可实现按天生成存储,定时删除日志


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
BY1EvMhY1VNb
最新推荐 更多