批处理bat监控流量

有时win机器运行脚本会卡死,进程又存在,则需要监控流量才实现自动恢复

NetworkTraffi

后缀改成.cs

安装在C:\NetworkTraffic:

%systemroot%\Microsoft.NET\Framework\v2.0.50727\csc /target:exe /debug- /optimize+ C:\NetworkTraffic\NetworkTraffic.cs

比如监控20分钟没流量则重启

@echo off
C:\Users\Administrator\NetworkTraffic.exe 本地连接 | findstr 本地连接 > C:\NetworkTraffic\tmp.log
for /f “tokens=6 delims=. ” %%i in (C:\NetworkTraffic\tmp.log) do echo %%i> C:\NetworkTraffic\Network.log
type C:\NetworkTraffic\net1.log > C:\NetworkTraffic\net2.log
type C:\NetworkTraffic\Network.log > C:\NetworkTraffic\net1.log
set /p TimeNow= < C:\NetworkTraffic\net1.log
set /p TimeAgo= < C:\NetworkTraffic\net2.log
set /A NetCharge = %TimeNow% – %TimeAgo%
echo %date:~0,10% %time:~0,8% 20分钟流量变化:%NetCharge% >> C:\NetworkTraffic\chargeNet.log
if 30 gtr %NetCharge% taskkill /F /IM xxxx.exe /T & echo %date:~0,10% %time:~0,8% 20分钟无流量变化 将重启xxxx >> C:\NetworkTraffic\Netrestart.log & ping -n 10 127.1 >nul 2>nul & timeout /t 10 & start “” “C:\AppleAppDownloader\xxxx.exe” & echo %date:~0,10% %time:~0,8% xxxx启动成功 >> C:\NetworkTraffic\Netrestart.log

 

 

文章分类 批处理, 流量监控

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*