【发布时间】:2014-08-03 09:28:50
【问题描述】:
我有一个计算机列表,我想根据 tcp 连接状态做一些事情。
我正在尝试检查 tcp 连接,如果错误日志为“1”,则写入行记录并跳到下一台计算机。
问题是当一台计算机没有 tcp 连接时,goto skip_action 命令会将脚本带到末尾并退出,而列表中的其他计算机则未处理。
我也尝试过使用goto :eof,它意外终止了脚本。
ipst.txt file:
1 10.1.1.10
3 10.1.3.10
8 10.1.3.10
这是批处理文件代码:
@echo off
setlocal enabledelayedexpansion
set computerslist=ipst.txt
for /f "usebackq tokens=1,2" %%A in ("%Computerslist%") do (
cls
set Station_Num=%%A
set Comp_IP=%%B
ping !Comp_IP! -n 1 | findstr "TTL"
if !errorlevel!==1 (
echo Station !Station_Num! .... !Comp_IP! ..................... No Communication.>>%log%
goto skip_action
)
echo Getting Administrator Credentials:
net use \\!Comp_IP! /USER:WORKGROUP\****** ******
echo.
xcopy file.txt \\!Comp_IP!\c\temp\
echo Disconneting Session From Remote Computer :
net use \\!Comp_IP! /DELETE /YES
:skip_action
echo end of working on !Station_Num!
)
echo end of script
【问题讨论】:
标签: batch-file goto