linux日志分割
1.编写脚本osgi.sh
#!/bin/bash
#this script run at 00:00,it's for cut osgi.out
#the nginx logs path
logs_path="/opt/usr/huangye/osgi/logs/"
logs_collect_path="/opt/usr/huangye/osgi_collect/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mkdir -p ${logs_collect_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
cp ${logs_path}osgi.out ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/osgi_$(date -d "yesterday" +"%Y%m%d").out
cp ${logs_collect_path}osgi.out ${logs_collect_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/osgi_$(date -d "yesterday" +"%Y%m%d").out
#kill -USR1 `cat /opt/usr/osgi/bin/osgi.pid`
echo "" > /opt/usr/huangye/osgi/logs/osgi.out
echo "" > /opt/usr/huangye/osgi_collect/logs/osgi.out
2.创建自动任务
》crontab -e
00 00 * * * /root/tools/osgi.sh