In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "script sharing of nginx log cutting". In daily operation, I believe many people have doubts about script sharing of nginx log cutting. The editor consulted all kinds of information and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "script sharing of nginx log cutting". Next, please follow the editor to study!
Implementation method one
#! / bin/bashLogs_path= "/ data/Application/nginx/logs" Pid_path= "/ data/Application/nginx/nginx.pid" Month= `date +% Ymury% m`Date = `date +% Yafei% mmure% d`time = `date +% H`WaitTime = $((24,60,60)) LogCut () {cd $Logs_path mkdir-p $Month while true do mv $Logs_path/access.log $Logs_path/$Month/access_$Date.log kill-USR1 `cat ${Pid_path} `done sleep $WaitTime return 0} case $1 instart) LogCut > / dev/null & Stop) kill-9 `ps aux | grep LogCut | grep-v grep | awk'{print $2}'`> / dev/null;; restart) kill-9 `ps aux | grep LogCut | grep-v grep | awk'{print $2}'` > / dev/null LogCut > / dev/null &; *) echo "Usage errored Please use" start "or" stop "or" restart "!" esac
Implementation method 2
Test environment:
# cat / etc/redhat-release Red Hat Enterprise Linux Server release 5.3 (Tikanga) # / opt/nginx/nginx-vnginx version: nginx/1.6.2
Code:
#! / bin/bash# = # chmod uplix / opt/nginx/cut_nginx_log.sh# crontab-e # 00 * / opt/nginx/cut_nginx_log.sh > / opt/nginx/logs/cut_nginx_log.log 2 > & opt/nginx/logs = LOGS_PATH= "/ opt/nginx/logs" ARCHIVE_YEAR=$ (date-d "yesterday"+% Y") ARCHIVE_MONTH=$ (date-d "yesterday"+% m") ARCHIVE_DATE=$ (date-d " Yesterday "" +% Y%m%d_%H%M%S ") if [- r / opt/nginx/nginx.pid] Then mkdir-p "${LOGS_PATH} / ${ARCHIVE_YEAR} / ${ARCHIVE_MONTH}" mv "${LOGS_PATH} / access.log"${LOGS_PATH} / ${ARCHIVE_YEAR} / ${ARCHIVE_MONTH} / access_$ {ARCHIVE_DATE} .log" kill-USR1 $(cat "/ opt/nginx/nginx.pid") sleep 1 gzip "${LOGS_PATH} / ${ARCHIVE_YEAR} / ${ARCHIVE_MONTH} / access_ ${ARCHIVE_DATE} .log "else echo" Nginx might be down "fi# = # Clean up log files older than 100 days# = # Change HOUSEKEEPING=1 to enable clean upHOUSEKEEPING=0KEEP_DAYS=100if [$HOUSEKEEPING= = 1] Then if [- d "${LOGS_PATH}"]; then find "${LOGS_PATH}"-type f-name "access_*.log.gz"-mtime + ${KEEP_DAYS}-exec rm-f {}\; fifi at this point, the study on "script sharing for nginx log cutting" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.