| 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『楼 主』:
 求助:用ping命令实现局域网内服务器监测的批处理
 
使用 LLM 解释/回答一下
  
刚学批处理没多久,对于BOSS的这个要求有点为难,请教各位了: 
要求: 
1)局域网内有40台服务器,要求用ping -l 10000相互连接,就是40*40对; 
2)用得到的ping结果取出“Average”值,针对每台的话,应该有40个“Average”值; 
3)对每台得到的40个“Average”值再进行求平均数得到一个“Average”值; 
4)40台就有40个相互ping求出的“Average”值; 
5)将得到的40个结果生成点状图,通过查看变化曲线以达到网络监测的目的。
 
(我的想法是在每台机器上跑一个批处理收集结果到一个机器上,再将40个结果导入到excel表中,再生成点状图。。。)
   谢谢。。。  
I've just started learning batch processing for a short time, and I'm a bit stuck with the boss's requirement. I'm asking you all for help: 
 
Requirement: 
1) There are 40 servers in the LAN. It's required to use ping -l 10000 to connect with each other, that is, 40*40 pairs; 
2) Take out the "Average" value from the obtained ping results. For each machine, there should be 40 "Average" values; 
3) Take the average of the 40 obtained "Average" values for each machine to get one "Average" value; 
4) There are 40 "Average" values obtained from mutual pings for 40 machines; 
5) Generate a dot chart from the obtained 40 results, and achieve the purpose of network monitoring by viewing the change curve. 
 
(My idea is to run a batch processing on each machine to collect results to one machine, then import the 40 results into an Excel sheet, and then generate a dot chart...) 
 
;):cool: Thanks... 
    
 
  
 |   
 | 
  2008-9-21 13:15 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 2 楼』:
 
 
使用 LLM 解释/回答一下
  
或是大家有什么更好的主意,欢迎提出来:-) 
Or everyone has any better ideas, welcome to put forward :-) 
    
 
  
 |   
 | 
  2008-9-21 13:15 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
 | 
  2008-9-21 13:40 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 4 楼』:
 
 
使用 LLM 解释/回答一下
  
针对一台机器ping其它机器的时间中提取出"Average"我已经得到了,但是现在是要对得到的这40个"Average"时间求和并求平均值/40,请赐教下: 
------------------------------------------------------- 
@echo off  
 
for /f %%i in (c:\build_pcs.txt) do ping -l 1000 %%i | find "Average =" >>e:\ping_Average_time.txt 
 
for /f "tokens=4 delims==" %%i in (e:\ping_Average_time.txt) do @echo %%i  
------------------------------------------------------- 
 
以上得到的结果例如: 
 
 145ms 
 164ms 
 147ms 
 179ms 
 168ms 
 
要如何求和,并算出平均数呢? 
To sum the 40 "Average" times and find the average divided by 40, you can use a batch script to handle the calculations. Here's an example of how you can modify the existing script to achieve this: 
 
```batch 
@echo off 
setlocal enabledelayedexpansion 
 
set sum=0 
set count=0 
 
for /f %%i in (c:\build_pcs.txt) do ( 
    ping -l 1000 %%i | find "Average =" >>e:\ping_Average_time.txt 
) 
 
for /f "tokens=4 delims==" %%i in (e:\ping_Average_time.txt) do ( 
    set /a sum=!sum! + %%i 
    set /a count+=1 
) 
 
set /a average=!sum! / !count! 
echo The average of the 40 Average times is: !average! ms 
endlocal 
``` 
 
This script first initializes a sum variable and a count variable. It then iterates through the lines in `e:\ping_Average_time.txt`, extracts the numerical part of the "Average" time, adds it to the sum, and increments the count. Finally, it calculates the average by dividing the sum by the count and displays the result. 
    
 
  
 |   
 | 
  2008-9-21 14:09 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 5 楼』:
 
 
使用 LLM 解释/回答一下
  
@echo off 
set sum=0 
for /f "delims=ms" %%a in (ping_Average_time.txt) do ( 
  set /a sum+=%%a 
) 
echo 平均值的和:%sum% 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
echo 平均值除以40的结果:%div1% 
set /a div2=sum/40 
echo 平均值整除40的结果:%div2% 
  
```@echo off 
set sum=0 
for /f "delims=ms" %%a in (ping_Average_time.txt) do ( 
  set /a sum+=%%a 
) 
echo Sum of the average values: %sum% 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
echo Result of average divided by 40: %div1% 
set /a div2=sum/40 
echo Result of average integer division by 40: %div2% 
``` 
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 14:42 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 6 楼』:
 
 
使用 LLM 解释/回答一下
  
呵呵,,谢谢HAT的帮助,另外可否给予些注释,以便我这个初学者好理解下啊? 
尤其以下两句啊? 
 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
Hehe, thank you for HAT's help. Also, can you give some comments so that I, a beginner, can understand? Especially the following two sentences? 
 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
    
 
  
 |   
 | 
  2008-9-21 16:00 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 7 楼』:
 
 
使用 LLM 解释/回答一下
  
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
由于在批处理中的/表示整除,所有用上面的方法动态生成一个vbs文件来计算除法。
 for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
在批处理中调用刚刚生成的那个vbs,把计算结果赋值给变量div1  
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/40 
Because in batch processing, / means integer division, so use the above method to dynamically generate a vbs file to calculate the division.
 for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
Call the just-generated vbs in batch processing and assign the calculation result to the variable div1  
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 16:19 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 8 楼』:
 
 
使用 LLM 解释/回答一下
  
前4个要求OK了,但是要怎么自动生成点状图呢? 
我的想法是:可否将结果导入到已经做好的Excel模板里,工作表2将工作表1得到的数据直接生成点状图? 
现在得到了一个TXT文件如下例(但如果直接得到Excel文件的话则会放在同一个单元格里?): 
---------------------------------------------------------- 
xty1UEA	2.186046512 
xtyP61C	2.162790698 
xtyP82C	2.023255814 
xty1UDA	1.837209302 
xtyPQ6C	1.465116279 
xtyP84C	2.348837209 
xtyPS7C	1.790697674 
xtyPQ3C	1.372093023 
xtyPQ2C	1.651162791 
xtyPS9C	2.790697674 
xtyPQ4C	1.395348837 
xtyPQ5C	2.093023256 
xtyPT0C	3.11627907 
xtyPT1C	2.11627907 
xtyPQ7C	1.627906977 
xtyPT2C	1.88372093 
xtyPR1C	2.418604651 
xtyPT3C	1.976744186 
xtyPR2C	2.302325581 
xtyPT4C	1.906976744 
xtyPT5C	2.395348837 
xtyPR3C	2.302325581 
xtyPR7C	3 
xtyPT6C	1.627906977 
xtyPR4C	2.906976744 
xtyPT7C	2.069767442 
xtyPT8C	2.093023256 
xtyPR5C	2.441860465 
xtyPR6C	2.372093023 
xtyPT9C	2.023255814 
xtyPU0C	2.279069767 
xtyPS3C	1.953488372 
xtyPS4C	2.302325581 
-------------------------------------------------------------- 
The first 4 requirements are okay, but how to automatically generate a dot plot? 
 
My idea is: Can the results be imported into the already made Excel template, and worksheet 2 directly generates a dot plot from the data obtained in worksheet 1? 
 
Now a TXT file is obtained as the following example (but if an Excel file is directly obtained, it will be placed in the same cell?): 
---------------------------------------------------------- 
xty1UEA	2.186046512 
xtyP61C	2.162790698 
xtyP82C	2.023255814 
xty1UDA	1.837209302 
xtyPQ6C	1.465116279 
xtyP84C	2.348837209 
xtyPS7C	1.790697674 
xtyPQ3C	1.372093023 
xtyPQ2C	1.651162791 
xtyPS9C	2.790697674 
xtyPQ4C	1.395348837 
xtyPQ5C	2.093023256 
xtyPT0C	3.11627907 
xtyPT1C	2.11627907 
xtyPQ7C	1.627906977 
xtyPT2C	1.88372093 
xtyPR1C	2.418604651 
xtyPT3C	1.976744186 
xtyPR2C	2.302325581 
xtyPT4C	1.906976744 
xtyPT5C	2.395348837 
xtyPR3C	2.302325581 
xtyPR7C	3 
xtyPT6C	1.627906977 
xtyPR4C	2.906976744 
xtyPT7C	2.069767442 
xtyPT8C	2.093023256 
xtyPR5C	2.441860465 
xtyPR6C	2.372093023 
xtyPT9C	2.023255814 
xtyPU0C	2.279069767 
xtyPS3C	1.953488372 
xtyPS4C	2.302325581 
-------------------------------------------------------------- 
    
 
  
 |   
 | 
  2008-9-21 22:10 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 9 楼』:
 
 
使用 LLM 解释/回答一下
  
忘了,还有个估计是网络问题,本来应该有40台机器得,但是收集到的结果却少了几台?看了下这几台的脚本是可以跑的,但是结果并没有传到统一的地方来? 
这是怎么回事呢? 
Forgot, there's also an estimated network issue. Originally, there should be 40 machines, but the collected results are a few less? I took a look, and the scripts for these few machines can run, but the results didn't get transmitted to the unified place? What's going on here? 
    
 
  
 |   
 | 
  2008-9-21 22:11 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 10 楼』:
 Re 8楼
 
使用 LLM 解释/回答一下
  
把你的数据中间的空白替换成tab 
打开Excel->数据->导入外部数据->...... 
Replace the spaces in your data with tabs. Open Excel -> Data -> Import External Data ->...... 
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 22:29 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 11 楼』:
 Re 9楼
 
使用 LLM 解释/回答一下
  
你实际应用中的代码是怎样的? 
你用什么方式把数据传到统一的地方来? 
What is the code in your actual application? How do you transfer data to a unified place? 
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 22:31 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 12 楼』:
 
 
使用 LLM 解释/回答一下
  
不是有40台机器吗?我在每台机器上设置了计划任务运行以下bat文件: 
----------------------------------------- 
@echo off  
 
if exist e:\ping_time.txt del /q e:\ping_time.txt 
if exist e:\ping_Average_time.txt del /q e:\ping_Average_time.txt 
if exist e:\ping_Average_time.xls del /q e:\ping_Average_time.xls 
 
for /f %%i in (e:\build_pcs.txt) do ping -l 1000 %%i | find "Average =" >>e:\ping_time.txt 
 
for /f "tokens=4 delims==" %%i in (e:\ping_time.txt) do @echo %%i >>e:\ping_Average_time.txt 
 
 
set sum=0 
for /f "delims=ms" %%a in (e:\ping_Average_time.txt) do ( 
  set /a sum+=%%a 
) 
echo 平均值的和:%sum% 
REM*****由于在批处理中的/表示整除,所以动态生成一个vbs文件来计算除法。***** 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/43 
REM*****在批处理中调用刚刚生成的那个vbs,把计算结果赋值给变量div1 ***** 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
echo %Computername%  %div1% >>\\xtyPR3c\ping_Average_time.txt 
-------------------------------------------------------------------- 
 
就把数据传到统一的地方来啊:-) 
当然最后也可以导出为一个xls文件,但是到xls后不会分成两列,而是一列不好统计啊?就想用个自动点的方法,导出到一个xls文件,并自动分成两列,最好是导到一个已经做好的模板的工作表1中,这样做好的模板就可以自动在工作表2生成曲线图了:-) 
Aren't there 40 machines? I set up a scheduled task on each machine to run the following bat file: 
----------------------------------------- 
@echo off  
 
if exist e:\ping_time.txt del /q e:\ping_time.txt 
if exist e:\ping_Average_time.txt del /q e:\ping_Average_time.txt 
if exist e:\ping_Average_time.xls del /q e:\ping_Average_time.xls 
 
for /f %%i in (e:\build_pcs.txt) do ping -l 1000 %%i | find "Average =" >>e:\ping_time.txt 
 
for /f "tokens=4 delims==" %%i in (e:\ping_time.txt) do @echo %%i >>e:\ping_Average_time.txt 
 
 
set sum=0 
for /f "delims=ms" %%a in (e:\ping_Average_time.txt) do ( 
  set /a sum+=%%a 
) 
echo 平均值的和:%sum% 
REM*****Since / in batch processing means integer division, dynamically generate a vbs file to calculate division.***** 
>"%temp%\MyDel.vbs" echo wscript.echo %sum%/43 
REM*****Call the just-generated vbs in batch processing and assign the calculation result to variable div1***** 
for /f %%a in ('cscript /nologo "%temp%\MyDel.vbs"') do set div1=%%a 
echo %Computername%  %div1% >>\\xtyPR3c\ping_Average_time.txt 
-------------------------------------------------------------------- 
 
Just transfer the data to a unified place :-) 
Of course, it can finally be exported to an xls file, but after exporting to xls, it won't be divided into two columns, but one column, which is not easy to count? I just want to use an automatic clicking method to export to an xls file and automatically divide into two columns. It's best to export to worksheet 1 of a pre-made template, so that the made template can automatically generate a curve chart in worksheet 2 :-) 
    
 
  
 |   
 | 
  2008-9-21 22:46 | 
  
 | 
 | 
 
fancyli622 
初级用户
 
  
 
  
  
积分 22 
发帖 10 
注册 2008-9-21 
状态 离线
 | 
『第 13 楼』:
 
 
使用 LLM 解释/回答一下
  
最后,还想反这个生成好的xls文件,自动发邮件给管理员? 
Finally, also want to reverse this generated xls file and automatically send an email to the administrator? 
    
 
  
 |   
 | 
  2008-9-21 22:48 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 14 楼』:
 Re 12楼
 
使用 LLM 解释/回答一下
  
先在出问题的几台机器上修改一下代码的最后一句,不要直接把文件>>到xtyPR3c,而是>>到本机试试。至于在xls中分成两列,你把%Computername%和%div1%中间的空格换成制表符试试。 
First, modify the last line of the code on the problematic machines. Instead of redirecting the file to xtyPR3c, redirect it to the local machine for testing. As for splitting into two columns in xls, try replacing the space between %Computername% and %div1% with a tab character. 
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 23:10 | 
  
 | 
 | 
 
HAT 
版主
 
        
 
  
  
积分 9023 
发帖 5017 
注册 2007-5-31 
状态 离线
 | 
『第 15 楼』:
 Re 13楼
 
使用 LLM 解释/回答一下
  
可以调用VBS来发邮件,google一下吧,类似的代码随处可见。 
Set cdo = CreateObject("CDO.Message") 
strCfg = "http://schemas.microsoft.com/cdo/configuration/" 
With cdo 
  .Sender = "发送者邮件地址" 
  .From = "发送者邮件地址" 
  .To = "接收者邮件地址" 
  .Fields("urn:schemas:mailheader:X-Priority") = 1  
  .Fields.Update  
  .Subject = "邮件标题" 
  .TextBody = "邮件内容" 
  .Configuration(strCfg & "SendUsing") = 2 
  .Configuration(strCfg & "smtpserver") = "发送邮件服务器地址" 
  .Configuration.Fields.Update 
  .Send 
End With  
 
如果需要发送附件,可以参考这个帖子:
 http://www.cn-dos.net/forum/viewthread.php?tid=29873
 Last edited by HAT on 2008-11-6 at 00:56 ]  
You can use VBS to send emails. Just Google it; similar code is everywhere. 
Set cdo = CreateObject("CDO.Message") 
strCfg = "http://schemas.microsoft.com/cdo/configuration/" 
With cdo 
  .Sender = "Sender's email address" 
  .From = "Sender's email address" 
  .To = "Recipient's email address" 
  .Fields("urn:schemas:mailheader:X-Priority") = 1  
  .Fields.Update  
  .Subject = "Email subject" 
  .TextBody = "Email content" 
  .Configuration(strCfg & "SendUsing") = 2 
  .Configuration(strCfg & "smtpserver") = "SMTP server address for sending emails" 
  .Configuration.Fields.Update 
  .Send 
End With  
 
If you need to send attachments, you can refer to this thread:
 http://www.cn-dos.net/forum/viewthread.php?tid=29873
 Last edited by HAT on 2008-11-6 at 00:56 ]  
    
 
  
  |  
                  
  
                      |   
 | 
  2008-9-21 23:13 | 
  
 |