2015-01-14 68 views
-1

我正在跟蹤多個電路。我通過從一臺機器ping到遠端的IP地址來執行此任務。我最近在此站點的幫助下添加了日誌記錄功能,但日誌增長過快,並且正在減慢從文本文件中提取信息的數據庫。是否有可能只記錄某些值的值。從超時的那些值開始。 在此先感謝記錄ping結果

這是日誌文件中生成的一小部分內容。我只想保持會話說超時。

星期四2015年1月15日 - 8:16:10.27 - 74.125.230.244 - RTT [284]

星期四2015年1月15日 - 8:16:12.60 - 74.125.230.244 - RTT [154]

星期四2015年1月15日 - 8:16:14.91 - 74.125.230.244 - RTT [154]

星期四2015年1月15日 - 8:16:21.65 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:23.74 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:29.36 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:31.86 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:35.36 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:40.36 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:45.36 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:48.36 - 74.125.230.244 - RTT [時控出]

星期四2015年1月15日 - 8:16:54.35 - 74.125.230.244 - RTT [超時]

星期四2015年1月15日 - 8:16:56.80 - 74.125.230.244 - RTT [287]

星期四2015年1月15日 - 8:16:59.18 - 74.125.230.244 - RTT [249]

@echo off 
TITLE = Circuit 1 
mode 40,20 
setlocal enableextensions enabledelayedexpansion 

rem Get address from command line 
set "address=74.125.230.244" 
if not defined address set "address=127.0.0.1" 

rem Configure levels and colors 
rem The format is initialValue:color in value descending format 
set "levels=9000:4F 178:E0 146:2F 0:E0" 

rem infinite loop 
for /l %%i in() do (
    rem retrieve information from ping command 
    set "rtt=Timed Out" 
    set "ttl=?" 
    for /f "tokens=3,4 delims==^<" %%a in (
     'ping -n 1 "%address%" ^| find "TTL="' 
    ) do for /f "tokens=1 delims=m" %%c in ("%%a") do (
     set /a "rtt=%%c" 
     set "ttl=%%b" 
    ) 

    rem retrieve color 
    set "color=" 
    for %%z in (%levels%) do for /f "tokens=1,2 delims=:" %%a in ("%%z") do (
     if not defined color if !rtt! geq %%a set "color=%%b" 
    ) 

    rem show information 
    if defined color color !color! 
    echo(!time! - %address% - rtt[!rtt!] 

    rem save to log 
    for /f "tokens=1-4 delims=.:-/ " %%a in ("!date!") do (
     >> "%%b-%%c-%%d_%%a_circuit1.txt" echo(!date! - !time! - %address% - rtt[!rtt!] 
    ) 

    rem wait and repeat the process 
    ping -n 3 localhost >nul 2>nul 
) 
+0

很可能。現在請透露祕密信息。通過編輯您的問題來示例說明您想要記錄的結果。 – Magoo

+0

@Magoo我不確定你需要什麼?問題是我可以只記錄超時響應。 – phifer2088

+0

**您**知道要保留的日誌文件中的行,以及您想要放棄的行。向我們展示您想要保留的行和您想要放棄的行的示例。如有必要,請將敏感信息替換爲泛型(如一系列xs)。我們無法讀懂你的想法。 – Magoo

回答

0

從理論上講,所有你需要做的是門正在執行的forecho至日誌:

.... 
echo(!time! - %address% - rtt[!rtt!] 

rem save to log 
if "!rtt!"=="Timed Out" for /f "tokens=1-4 delims=.:-/ " %%a in ("!date!") do (
    >> "%%b-%%c-%%d_%%a_circuit1.txt" echo(!date! - !time! - %address% - rtt[!rtt!] 
) 
....