bash:GNU bash, version 4.1.2(2)-release (x86_64-redhat-linux-gnu)
需求是统计niginx的access.log的总流量
脚本1正常
代码: 全选
sum=0
while read line
do
SIZE=`echo $line|awk '{print $10}'|egrep -v "^\""`
expr $SIZE + 1 &>/dev/null
[ $? -eq 0 ]&&{
#echo $SIZE
sum=$(($SIZE+$sum))
}
done<./access.log
echo $sum
代码: 全选
sum=0
while read line
do
SIZE=`echo $line|awk '{print $10}'|egrep -v "^\""`
expr $SIZE + 1 &>/dev/null
[ $? -eq 0 ]&&{
#echo $SIZE
sum=$(($sum+$SIZE))
}
done<./access.log
echo $sum
调试脚本2时 卡在这个地方
代码: 全选
+ read line
++ egrep -v '^"'
++ awk '{print $10}'
++ echo 1.12.77.113 - - '[18/Apr/2018:10:22:50' '+0800]' '"GET' / 'HTTP/1.1"' 200 57700 '"http://39.105.19.97/?page_id=10"' '"Mozilla/5.0' '(Windows' NT '10.0;' 'Win64;' 'x64)' AppleWebKit/537.36 '(KHTML,' like 'Gecko)' Chrome/65.0.3325.181 'Safari/537.36"'
+ SIZE=57700
+ expr 57700 + 1
+ '[' 0 -eq 0 ']'
+ sum=31596953
+ read line
++ egrep -v '^"'
++ awk '{print $10}'
++ echo 1.12.77.113 - - '[18/Apr/2018:10:27:28' '+0800]' '"x03"' 400 174 '"-"' '"-"'
+ SIZE=
+ expr + 1
+ '[' 0 -eq 0 ']'
access.sh: line 8: 31596953+: syntax error: operand expected (error token is "+")
[root@bbs logs]#