#!/usr/bin/env python ``` 處理訪問日誌,篩選時間大於1秒的請求 ``` with open(`test.log`,`a+`,encoding=`utf-8`) as f_a: with open(`wkxz-api.access.log`) as f: for line in f.readlines(): if line[-2:] == "- " : num =float(line[-7:-2]) else: num=float(line[-6:]) if num >= 1.000 : f_a.write(line)
#!/bin/bash cat wkxz-api.access.log | while read LINE do #echo $LINE time=`echo $LINE| awk `{print $NF}` | awk `{print int($0)}`` #echo $time if [ "$time" -ge "1" ];then echo $LINE >> wkxz-api.log fi done