Пакетный скрипт приостанавливается во время работы

Вопрос:

Я написал пакетный скрипт, который выглядит следующим образом:

@echo off

setlocal enableextensions enabledelayedexpansion
set "outfile=wmic-full-output.txt"

for /L %%y in (73,1,79) do (
for /L %%z in (1,1,254) do (

echo ********************************************************* >> "!outfile!"

set "node=172.22.%%y.%%z"

echo !node! >> "!outfile!"

ping -n 1 -l 1 -w 1 !node! | find "Packets" >> "!outfile!"
if not errorlevel 1 (
nbtstat -A !node! >> !outfile!
nbtstat -A !node! | find /i "Host not found." >nul 2>&1 && ( echo Not a Windows Machine >> !outfile! ) || (

for /f "tokens=2-7 delims=," %%a in (
'wmic /node:"!node!" computersystem get domain^,manufacturer^,model^,name^,systemtype^,username^,wakeuptype /format:csv ^| find /i "!node!"'
) do (
set "_domain=%%a"
set "_manufacturer=%%b"
set "_model=%%c"
set "_name=%%d"
set "_systemType=%%e"
set "_userName=%%f"
for %%j in (!_username!) do (set "_username=%%j")
if "!_username!"=="6" (set "_username=Not Available")
)


for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" bios get serialNumber^,version /format:csv ^| find /i "!node!"'
) do (
set "_serialNumber=%%a"
)

for /f "tokens=2-3 delims=," %%a in (
'wmic /node:"!node!" os get name^,totalvisiblememorysize^,version /format:csv ^| find /i "!node!"'
) do (
set "_osName=%%a"
for /f "tokens=1 delims=|" %%j in ("!_osName!") do (set "_osName=%%j")
set "_memory=%%b"
)

for /f "tokens=2 delims=," %%a in (
'wmic /node:"!node!" cpu get name^,version /format:csv ^| find /i "!node!"'
) do (
set "_cpu=%%a"

echo HostName= !_name! >> "!outfile!"
echo Domain= !_domain!>> "!outfile!"
echo UserName= !_userName! >> "!outfile!"
echo Manufacturer= !_manufacturer! >> "!outfile!"
echo Model= !_model! >> "!outfile!"
echo SystemType= !_systemType! >> "!outfile!"
echo SerialNumber= !_serialNumber! >> "!outfile!"
echo OperatingSystem= !_osName! >> "!outfile!"
echo RAM= !_memory! >> "!outfile!"
echo Processor= !_cpu! >> "!outfile!"

)
))
))

Когда вышеприведенный скрипт выполняется на сервере Windows, после успешного выполнения до 172.22.73.12 он приостанавливается навсегда. Когда outfile наблюдаются содержание, последний результат записывается в выходной nbtstat -A 172.22.73.13.

Что-то не так с сценарием?

Лучший ответ:

Проверьте это:

@echo off

setlocal enableextensions enabledelayedexpansion
    set "outfile=wmic-full-output.txt"

    for /L %%y in (73,1,79) do (
    for /L %%z in (1,1,254) do (

    echo ********************************************************* >> "!outfile!"

    set "node=172.22.%%y.%%z"

    echo !node! >> "!outfile!"

    ping -n 1 -l 1 -w 1 !node! | find /i "TTL=" >> "!outfile!"
    if not errorlevel 1 (
    nbtstat -A !node! >> !outfile!
    nbtstat -A !node! | find /i "Host not found." >nul 
    if errorlevel 1 (


    for /f "tokens=2-7 delims=," %%a in (
        'wmic /node:"!node!" computersystem get domain^,manufacturer^,model^,name^,systemtype^,username^,wakeuptype /format:csv ^| find /i "!node!"'
    ) do (
        set "_domain=%%a"
    set "_manufacturer=%%b"
        set "_model=%%c"
        set "_name=%%d"
        set "_systemType=%%e"
        set "_userName=%%f"
    for %%j in (!_username!) do (set "_username=%%j")
    if "!_username!"=="6" (set "_username=Not Available")
     )


    for /f "tokens=2 delims=," %%a in (
        'wmic /node:"!node!" bios get serialNumber^,version /format:csv ^| find /i "!node!"'
    ) do (
        set "_serialNumber=%%a"
    )

    for /f "tokens=2-3 delims=," %%a in (
        'wmic /node:"!node!" os get name^,totalvisiblememorysize^,version /format:csv ^| find /i "!node!"'
    ) do (
        set "_osName=%%a"
    for /f "tokens=1 delims=|" %%j in ("!_osName!") do (set "_osName=%%j")
    set "_memory=%%b"
    )

    for /f "tokens=2 delims=," %%a in (
        'wmic /node:"!node!" cpu get name^,version /format:csv ^| find /i "!node!"'
    ) do (
        set "_cpu=%%a"

    echo HostName= !_name! >> "!outfile!"
    echo Domain= !_domain!>> "!outfile!"
    echo UserName= !_userName! >> "!outfile!"
    echo Manufacturer= !_manufacturer! >> "!outfile!"
    echo Model= !_model! >> "!outfile!"
    echo SystemType= !_systemType! >> "!outfile!"
    echo SerialNumber= !_serialNumber! >> "!outfile!"
    echo OperatingSystem= !_osName! >> "!outfile!"
    echo RAM= !_memory! >> "!outfile!"
    echo Processor= !_cpu! >> "!outfile!"

    )

)
)
)
)
echo done
pause

Оцените статью
TechArks.Ru
Добавить комментарий