標籤:nginx mongodb
與大家一起學習、交流,並希望能夠指出不足之處。
#!/bin/bash# This script run at 00:00# The Nginx logs path# zhengyansheng time:2014-08-27logs_path="/usr/local/nginx/logs/"access_dir="/usr/local/nginx/logs/Insert_mongodb"mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m"+"%d")mv $logs_path/access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m"+"%d")/access_$(date -d "yesterday" +"%Y%m%d%H%M").logcat ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m"+"%d")/access_$(date -d "yesterday" +"%Y%m%d%H%M").log > $logs_path/access_mongo.log/usr/local/nginx/sbin/nginx -s reloadcat $logs_path/access_mongo.log | while read line;docookieId=`echo $line |awk -F "uid=" ‘{print $2}‘ | awk ‘{print $1}‘ | grep -v "^$"`ip=`echo $line | awk ‘{print $3}‘`appKey=`echo $line | awk ‘{print $1}‘`visidate=`echo $line | awk ‘{print $2}‘ | awk -F "[" ‘{print $2}‘`#visidate=`echo $line | gawk -F‘?id=‘ ‘{ print $2 }‘ |cut -d‘&‘ -f1`browsertype=`echo $line | awk -F "\"" ‘{print $6}‘`refer=`echo $line | awk -F "\"" ‘{print $4}‘`os=`echo $line | awk -F "\"" ‘{print $6}‘ |awk ‘{print $1}‘`videoID=`echo $line | gawk -F‘?id=‘ ‘{ print $2 }‘ |cut -d‘&‘ -f1`#videoID=`echo $line | awk -F "\"" ‘{print $2}‘ | awk -F "/?id=" ‘{print $2}‘|awk -F "&" ‘{print $1}‘|awk ‘{print $1}‘`#插入到正表中#sql="db.user.visit.data.insert({browsertype:‘$browsertype‘,cookieId:‘$cookieId‘,appKey:‘$appKey‘,ip:‘"$ip"‘,os:‘"$os"‘,referer:‘"$refer"‘,videoId:parseInt(‘$videoID‘),visitdate:ISODate(‘$visidate‘)})"sql="db.user.visit.data.insert({browsertype:‘$browsertype‘,cookieId:‘$cookieId‘,appKey:‘$appKey‘,ip:‘"$ip"‘,os:‘"$os"‘,referer:‘"$refer"‘,videoId:‘$videoID‘,visitdate:ISODate(‘$visidate‘)})"echo "$sql" >> $logs_path/nginx_log_mongo.txtdonecat $logs_path/nginx_log_mongo.txt | mongo 192.168.0.200:27018/ubs -u vmsdd -p ‘123456‘mv $logs_path/nginx_log_mongo.txt $logs_path/nginx_log_mongo_bak.txtrm -rf $logs_path/nginx_log_mongo_bak.txt
本文出自 “鄭彥生” 部落格,請務必保留此出處http://467754239.blog.51cto.com/4878013/1550502
線上的nginx、mongodb指令碼