Linux General automatic log cleanup script 1. this article is a simplified script for automatic system deployment. The main function is to clear logs from all directories. based on the given log directory, the deletion time is combined with crontab to clean the logs. after cleaning is completed, the logs are cleared by month in/var/log/deltelog... linux General automatic log cleanup script 1. this article is a simplified script for automatic system deployment. The main function is to clear logs from all directories. based on the given log directory, the deletion time is combined with crontab to clean up the log. after the cleaning is complete, generate a monthly cleanup log in/var/log/deltelog/. 3. because the script uses mtime (last modification time) to delete expired backups, shell tips are not restricted by file names. find-type f-print outputs the searched files based on line breaks or spaces, and different responses are made under different sh, if you do not perform the delete change operation with xargs, The-print0 value must be added. If null is used as the boundary symbol, you can marry xargs-o to format the input and use the find statement following the minimum result set principle. the find expression is left to right, make sure that the filter symbol on the leftmost side can filter the maximum data. you can add shell scripts to crontab as needed #! /Bin/sh ########################### delete log blog.duplicatedcode.com # in_day_num: like 1 2 is delete 2day ago logs # in_log_path like tomcat log home ########################## # in_log_path =$ {1} in_day_num =$ {2} tmp_delete_log =/var/log/deletelog/"'date + % Y % M '. log "deleteLog () {inner_num =$ {1} # find log echo "['Date']> start delete logs ---" >>>$ tmp_delete_log find $ {in_log_path}-type f-mtime ${inner_num}-print0 | xargs-0 rm-rf echo "['Date']> end delete logs ---" >>> $ tmp_delete_log} init () {mkdir-p/var/log/deletelog/} main () {init if [-z $ {in_log_path}]; then echo "['Date']> error log_path not init ---"> $ tmp_delete_log return fi inner_day_num = + 7 if [[-n $ {in_day_num}] & [[$ {in_day_num}-ge 1]; then $ {inner_day_num }=$ {in_day_num} fi deleteLog $ {inner_day_num} main
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.