In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Shell how to achieve automatic compression processing log files", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Shell how to achieve automatic compression processing log files" bar!
Shell handles logs and automatically retains logs for 30 days. If logs for more than 14 days are automatically compressed and stored in gz format, this can save disk space and back up logs regularly. I use log files as an example here, and other requirements can also be adjusted according to the content of the script.
#! / bin/sh# (c) Copyright 2012 Eric. All rights reserved.## Logs expired 30 days.## * cron# 1 6 * / bin/sh / var/app/shell/logs_arrange.sh > / var/app/shell/cron_logs_arrange.log#### # TODAY= `date +% s` # how many days ago will the logs to be zipPK_DAYS_AGO=14PK_DATEDIFF= `expr ${PK_DAYS_AGO}\ * 86400`PK _ EXT=gz# how many days ago will the logs to be removedDAYS_AGO=30DATEDIFF= `expr ${DAYS_AGO}\ * 86400`cleanDir () {directory=$1if [[- d ${directory}]] Thenfor file in `ls-1 ${directory} | grep-v '.log $' `; doctime= `stat-c% Y {directory} / ${file} `extname= `expr ${TODAY}-${ctime} `extname= `ls ${directory} / ${file} | awk-F'.'{printf $NF} '`if [[${extname}! = ${PK_EXT}]]; thenif [[- f ${directory} / ${file}]] Thenzipta= `expr ${timediff}-${PK_DATEDIFF} `if [[${zipta}-gt 0]]; thenecho "Package ${directory} / ${file}" gzip-f ${directory} / ${file} > ${directory} / ${file}. ${PK_EXT} fififiif [[- f ${directory} / ${file}]]; thendelta= `expr ${timediff}-${DATEDIFF} `if [[${delta}-gt 0]] Thenecho "Removing ${directory} / ${file}" rm-rf ${directory} / ${file} fifidonefi} cleanDir "/ var/app/logs/webapps/admin" cleanDir "/ var/app/logs/webapps/api" cleanDir "/ var/app/logs/webapps/pos" Thank you for reading. That's what Shell says about how to compress log files automatically. After the study of this article, I believe that we have a deeper understanding of how to achieve automatic compression of Shell to deal with log files, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.