1. du -hxa --max-depth=1 查看當前的文件大小(-a 能查看所有)nginx
2. cat /dev/null > file.log的方式清空日誌shell
3. 清理日誌tomcat
5 3 * * * sh /data/shell/clean_log.shbash
#!/bin/bash find /data/logs -type f -mtime +6 | xargs rm -rf find /usr/local/tomcat/logs -type f -mtime +6 | xargs rm -rf nohup find /data/logs/ -path /data/logs/nginx -prune -o -type f |grep -v gz|grep -Ev "*.log$" | xargs gzip & cat /dev/null > /data/rpc/bin/c:/root/zkregisterservice.log cat /dev/null > /root/c:/root/zkregisterservice.log cat /dev/null > /data/rpc/logs/rpc.log
nginx_error_num(){ LOG_FILE="/data/logs/nginx/access/log" TODAY=`date "+%Y:%H:"` MINUTE=`date +%M -d '-1 minute'` GREP_TIME=${TODAY}${MINUTE} if [ -f "${LOG_FILE}" ]; then N=`tail -n50000 ${LOG_FILE} | grep "${key}" | awk -F'\t' '$5!="200"' | wc -l` else N=0 fi echo $N } 統計日誌中的某一個接口最近一分鐘的失敗 date "+%Y:%H:" date +%M -d '-1 minute' tail -n50 /data/logs/nginx/access/log | grep "shutupinfos.action" | awk -F'\t' '$5!="200"' | wc -l