Linux 好用shell脚本集合

LogScrolling.sh

#!/bin/bash
cp /var/jfb/log/nginx/access_log.log /var/jfb/log/nginx/access_log_`date -d '-1 day' +%Y-%m-%d`.log
echo "" > /var/jfb/log/nginx/access_log.log

AccessCount.sh

#!/bin/bash
logName=/var/jfb/log/nginx/access_log_`date -d '-1 day' +%Y-%m-%d`.log
accessCount=`wc -l $logName |cut -d " " -f 1`
ipCount=`awk '{ip[$1]++}END{for(i in ip){print i,ip[i]}}' $logName |wc -l`
echo "access count is :${accessCount}"
echo "ip count is :${ipCount}"
for i in {0..23};
do 
	if [ $i -lt 10 ];then
		accessHourCount[$i]=`grep /2015:0${i} ${logName} |wc -l`
		ipHourCount[$i]=`grep /2015:0${i} ${logName} |awk '{ip[$1]++}END{for(i in ip){print i,ip[i]}}' |wc -l`
		echo "${i} Hour accessCount is :${accessHourCount[$i]}"
		echo "${i} Hour ipCount is :${ipHourCount[$i]}"
	else
		accessHourCount[$i]=`grep /2015:${i} ${logName} |wc -l`
		ipHourCount[$i]=`grep /2015:${i} ${logName} |awk '{ip[$1]++}END{for(i in ip){print i,ip[i]}}' |wc -l`
		echo "${i} Hour accessCount is :${accessHourCount[$i]}"
		echo "${i} Hour ipCount is :${ipHourCount[$i]}"
	fi
done

相关推荐