简体   繁体   English

Batch / cmd:将ping日志保存到文件中,然后获取摘要段落

[英]Batch/cmd: saving ping logs to a file and getting the summary paragraph afterwards

I'm trying to use ping to monitor my internet connection overnight and watch for connection dropouts, packet loss, latency spikes, and so on. 我正在尝试使用ping通宵监视我的Internet连接,并观察连接丢失,数据包丢失,等待时间尖峰等。 I have a batch file that pings google each second and records the results to a file: 我有一个批处理文件,每秒ping Google并将结果记录到一个文件中:

@echo off
    ping -t www.google.com|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!time! !data!)&ping -n 2 localhost>nul" > ping_logs_google.txt

And I get output like this: 我得到这样的输出:

16:36:50.47 Pinging www.google.com [209.85.202.106] with 32 bytes of data:
16:36:51.50 Reply from 209.85.202.106: bytes=32 time=31ms TTL=47
16:36:52.52 Reply from 209.85.202.106: bytes=32 time=31ms TTL=47
16:36:53.54 Reply from 209.85.202.106: bytes=32 time=30ms TTL=47
16:36:54.58 Reply from 209.85.202.106: bytes=32 time=29ms TTL=47
16:36:55.61 Reply from 209.85.202.106: bytes=32 time=32ms TTL=47
16:36:56.64 Reply from 209.85.202.106: bytes=32 time=32ms TTL=47

.. and so on. .. 等等。 However, when I press Ctrl-C or whatever to stop the task, I want to get the summary paragraph at the end. 但是,当我按Ctrl-C或其他任何方式来停止任务时,我想在最后得到摘要段落。 The one that looks like this: 看起来像这样的一个:

Ping statistics for 209.85.202.106:
    Packets: Sent = 9, Received = 9, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 29ms, Maximum = 34ms, Average = 30ms
Control-C
^C

Now, this does work when I press Ctrl-C after running just "ping -t www.google.com" in the command window itself -- it just doesn't work when I run it from the batch file. 现在,当我仅在命令窗口中运行“ ping -t www.google.com”后按Ctrl-C时,此方法就可以工作-当我从批处理文件运行该命令时,它不起作用。 How do I make it so that I get the summary paragraph at the end when I'm finished with the batch file? 如何使批处理文件结束后显示摘要段落?

Instead of running continuously with -t , replace with " -n 100 ", where "100" is the number of times it will ping (or 1000 if you like). 而不是用-t连续运行,而是用“ -n 100 ”代替,其中“ 100”是它将ping的次数(或者,如果需要,则为1000)。 This will give you the summary at the end of your output file the same way it does in the command window. 就像在命令窗口中一样,这将在输出文件的末尾提供摘要。 However, you'll want to remove any pauses, etc. and just it rip. 但是,您将希望删除所有暂停等内容,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM