亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標題:
求助 shell獲取log最新一條記錄的某個字段
[打印本頁]
作者:
tasteoftime_90
時間:
2014-07-30 16:42
標題:
求助 shell獲取log最新一條記錄的某個字段
想請教的是 譬如說我的log是這樣:
1.log
2.log
3.log
4.log
5......
log按時間順序?qū)懭?.log 2.log 3.log 4.log 5......,log里邊的內(nèi)容為:
2013-09-26.21:53:39,****IP:192.168.1.1,Bytes:123456/s***************************************
2013-09-26.21:53:39,****IP:192.168.2.1,Bytes:123456/s***************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,*******************************************
2013-09-26.21:53:39,****IP:192.168.1.1,Bytes:123456/s***************************************
2013-09-26.21:53:39,****IP:192.168.2.1,Bytes:123456/s***************************************
2013-09-26.21:53:39,*******************************************
我需要一個shell幫我我輸出最新一條192.168.2.1的Bytes記錄(即“123456”這串數(shù)字)
謝謝啦!
作者:
tasteoftime_90
時間:
2014-07-30 16:50
本帖最后由 tasteoftime_90 于 2014-07-30 16:51 編輯
log內(nèi)容的時間是不一樣的 例子沒舉好 如下:
2013-09-26.21:53:39,****IP:192.168.1.1,Bytes:123456/s***************************************
2013-09-26.21:53:42,****IP:192.168.2.1,Bytes:123456/s***************************************
2013-09-26.21:53:43,*******************************************
2013-09-26.21:53:44,*******************************************
2013-09-26.21:53:45,*******************************************
2013-09-26.21:53:46,*******************************************
2013-09-26.21:53:47,*******************************************
2013-09-26.21:53:48,*******************************************
2013-09-26.21:53:49,*******************************************
2013-09-26.21:53:50,*******************************************
2013-09-26.21:53:51,*******************************************
2013-09-26.21:53:52,*******************************************
2013-09-26.21:53:53,****IP:192.168.1.1,Bytes:123456/s***************************************
2013-09-26.21:53:54,****IP:192.168.2.1,Bytes:123456/s***************************************
2013-09-26.21:53:55,*******************************************
作者:
q1208c
時間:
2014-07-30 16:53
本帖最后由 q1208c 于 2014-07-30 16:53 編輯
for log in `ls -r *.log`;do tac $log | grep -m1 '192.168.2.1' ;done | head -n1 | sed '.*IP:192.168.2.1,Bytes:\([0-9]\+\)\/s.*/\1/'
復(fù)制代碼
我沒測試過.
作者:
yinyuemi
時間:
2014-07-30 16:55
回復(fù)
2#
tasteoftime_90
tac file | awk -F'[,/]' '$2~"192.168.2.1"{print gensub(/Bytes:/,"",1,$(NF-1));exit}'
作者:
dn833
時間:
2014-07-30 19:13
while : ;do tail -f *.log|grep -Po '(?<=192.168.1.1,Bytes:)\d+';done
復(fù)制代碼
作者:
jason680
時間:
2014-07-30 22:02
回復(fù)
1#
tasteoftime_90
try this way and easy to know what you want
$ awk 'match($0,/
IP:
192[.]168[.]1[.]1,
Bytes:
([0-9]+)/,a){N=a[1]}END{print N}' FILE
123456
作者:
tasteoftime_90
時間:
2014-07-31 10:46
本帖最后由 tasteoftime_90 于 2014-07-31 10:48 編輯
想再請教下 如果日志是( ****IP:192.168.2.1: ************Bytes 654321, Bytes/s 123456,**************** )*代表其他一些字符串,想取Bytes/s 123456中123456這個字符串,請問剛剛的shell對應(yīng)該怎么修改?
回復(fù)
4#
yinyuemi
作者:
tasteoftime_90
時間:
2014-07-31 10:54
想再請教下 如果日志是:
( ****IP:192.168.2.1: ************Bytes 654321, Bytes/s 123456,**************** ) *代表其他一些字符串
想取Bytes/s 123456中123456這個字符串,剛剛的shell對應(yīng)該怎么修改?
*號的這些其他字符串怎么用通配符表示?
謝謝!
回復(fù)
6#
jason680
作者:
Shell_HAT
時間:
2014-07-31 10:56
回復(fù)
8#
tasteoftime_90
sed -r 's#.*Bytes/s ([0-9]+),.*#\1#' a.txt
復(fù)制代碼
作者:
Shell_HAT
時間:
2014-07-31 11:00
回復(fù)
7#
tasteoftime_90
grep -Po '(?<=Bytes/s )\d+' a.txt
復(fù)制代碼
作者:
tasteoftime_90
時間:
2014-07-31 11:07
試了一下 這個的話會把整個日志所有的Bytes/s 123456都給輸出來 沒有過濾掉192.168.1.1的 我只需要最新一條記錄即可 謝謝!
回復(fù)
9#
Shell_HAT
作者:
Shell_HAT
時間:
2014-07-31 11:14
回復(fù)
11#
tasteoftime_90
稍微修改一下4樓的代碼就行了
tac a.txt | awk -F'[,]' '$1~"192.168.2.1"{print gensub(/ Bytes\/s /,"",1,$(NF-1));exit}'
復(fù)制代碼
作者:
jason680
時間:
2014-07-31 11:31
回復(fù)
8#
tasteoftime_90
/IP:192[.]168[.]1[.]1
,
Bytes:([0-9]+)/
change to ...
/IP:192[.]168[.]1[.]1
:.*
Bytes:([0-9]+)/
作者:
tasteoftime_90
時間:
2014-07-31 11:31
輸出來的是空值 沒有任何結(jié)果?
回復(fù)
12#
Shell_HAT
作者:
Shell_HAT
時間:
2014-07-31 11:33
回復(fù)
14#
tasteoftime_90
把你的測試數(shù)據(jù)發(fā)出來我試試
作者:
tasteoftime_90
時間:
2014-07-31 12:31
test.txt.rar
(782 Bytes, 下載次數(shù): 1)
2014-07-31 12:30 上傳
點擊文件名下載附件
麻煩啦!
回復(fù)
15#
Shell_HAT
作者:
Shell_HAT
時間:
2014-07-31 12:37
回復(fù)
16#
tasteoftime_90
tac 2.txt | awk -F, '$2~"192.168.2.1"{print gensub(/ bytes\/s /,"",1,$(NF-3));exit}'
復(fù)制代碼
作者:
itfly3
時間:
2014-07-31 13:01
tac t |awk -F '[:,/]' '/192.168.2.1/{print $7;exit}'
作者:
jcdiy0601
時間:
2014-07-31 15:01
egrep --color 'IP:192.168.2.1' test|sort -rn|head -1|sed -e 's/.*Bytes://'|awk -F'/' '{print $1}'
作者:
tasteoftime_90
時間:
2014-08-01 15:51
可以使用 謝謝 能稍微解釋下么 新手 另外想請教下有沒可能實現(xiàn) 在一臺設(shè)備上執(zhí)行腳本 收集多臺設(shè)備的執(zhí)行反饋信息
作者:
Shell_HAT
時間:
2014-08-01 17:03
回復(fù)
20#
tasteoftime_90
可以配置好ssh信任,然后用ssh獲取遠程機器信息
歡迎光臨 Chinaunix (http://www.72891.cn/)
Powered by Discuz! X3.2