自动清理带时间戳的log脚本
2017-04-01 10:15
351 查看
最近因为服务器上大量的带时间戳的日志存放过多,导致服务器上磁盘空间不够,因此就写了一个清理日志的脚本用于清理日志:
#!/bin/bash #logs_clenup.sh:Used to clean up logs #00 00 1 * * /usr/local/scripts/logs_clenup.sh #writer jiangtao #histor #2017.3.31 ########PATH######## app_dir=/usr/local/scripts/text_app_dir logs_dir=/data/logs/clrnup_logs two_month_ago=$(date -d '-2 month' +%Y-%m) datetime=$(date +"%Y-%m-%d") datetime_dir=$logs_dir/"$datetime" logs_dir_path=$(find $app_dir -type d -name 'logs' -print) if [ ! -e "$datetime_dir" ];then mkdir -p $datetime_dir fi ########PATH######## echo "============================ start cleanup logs `date +"%Y-%m-%d %H:%M:%S"`" | tee -a $datetime_dir/logs_clenup_${datetime}.log for i in $logs_dir_path do rm -rf $i/*$two_month_ago* echo "`date` $i cleanup success" | tee -a $datetime_dir/logs_clenup_${datetime}.log done if [ $? -eq 0 ];then echo "============================ end cleanup logs `date +"%Y-%m-%d %H:%M:%S"`" | tee -a $datetime_dir/logs_clenup_${datetime}.log else echo "cleanup logs fail!" | tee -a $datetime_dir/logs_clenup_${datetime}.log fi find $logs_dir -type f -ctime +30 -name "logs_clenup_*" -exec rm -vf {} \;
相关文章推荐
- MSsql每天自动备份数据库并每天自动清除log的脚本
- 自动清理IIS日志文件的脚本
- 游戏日志自动清理脚本
- Shell脚本自动备份MySQL到FTP并定期清理过期备份
- python 备份和自动清理过期备份脚本
- 自动清理 IIS 日志的脚本
- 虚拟化--050 vsphere【新提醒】Windows虚拟机10分钟自动同步时间脚本虚拟人工作室 - 虚拟人培训中心
- MySQL binlog 自动清理脚本
- linux通用自动清理日志脚本
- 自动清理日志文件脚本
- ant脚本打jar包 自动获取时间以及项目svn版本号
- Oracle自动导出脚本(WINDOWS停的,导出文件名自动加上日期和时间)
- windows下mysql自动备份压缩打包时间命名批处理脚本
- 自动清理垃圾的脚本.bat
- Linux下Oracle归档日志自动清理脚本代码(sh)
- MSsql每天自动备份数据库并每天自动清除log的脚本
- 数据库的自动作业清理日志脚本
- 我的一个学生在运维工作中写的自动日志清理脚本程序
- 【BASH】自动清理rman备份文件的脚本
- DB2归档日志的开启已经自动备份后清理归档的脚本