CMD/BAT - [решено] nslookup для парка ПК

Аватара пользователя
Iska

Re: CMD/BAT - [решено] nslookup для парка ПК

Сообщение Iska »

Цитата Iska:



HFShak, я был несколько ошарашен, когда увидел вывод Вашей «nslookup.exe»: в stdout в Ansi, в stderr — в OEM.
CMD/BAT - [решено] nslookup для парка ПК




Спасибо! Есть небольшая проблема...

Все записывает правильно, до того момента пока не находит ПК в домене. После этого он всегда пишет "ПК не найден в домене"....



Т.е.:



pc.txt:

NAMEPC1

NAMEPC2

NAMEPC3

NAMEPC1

...





Out.txt:

NAMEPC1 = 10.1.1.15

NAMEPC2 = 10.1.1.23

NAMEPC3 = Не найден

NAMEPC1 = Не найден

...





В чем причина?
Аватара пользователя
Iska

Re: CMD/BAT - [решено] nslookup для парка ПК

Сообщение Iska »

HFShak, посмотрел.



Попробуйте добавить:



Код:

Код: Выделить всё

				>nul copy nul "%sStdOut%"
				>nul copy nul "%sStdErr%"

перед:



Код:

Код: Выделить всё

				nslookup.exe "%%i" 1>"%sStdOut%" 2>"%sStdErr%"
Аватара пользователя
HFShak

Re: CMD/BAT - [решено] nslookup для парка ПК

Сообщение HFShak »

Не помогло, тоже самое...

Переменный задал такие:



set sFileSource=%userprofile%\desktop\pc.txt

set sLog=%userprofile%\desktop\Out.txt



call :GetTemporaryName

set sStdOut=%userprofile%\desktop\StdOut.txt



call :GetTemporaryName

set sStdErr=%userprofile%\desktop\StdErr.txt



Созданные текстовые файлы текстовые отправил через ЛС.
Аватара пользователя
HFShak

Re: CMD/BAT - [решено] nslookup для парка ПК

Сообщение HFShak »

HFShak, добрался до домена, посмотрел. Проблему подтверждаю.



Добавил принудительное обнуление переменной окружения «sError». Попробуйте теперь так:


читать дальше »

Код: Выделить всё

@echo off
setlocal enableextensions enabledelayedexpansion
set sFileSource=%~1
set sLog=%~2
call :GetTemporaryName
set sStdOut=%TemporaryName%
call :GetTemporaryName
set sStdErr=%TemporaryName%
if defined sFileSource (
	if defined sLog (
		if exist "%sFileSource%" (
			>nul copy nul "%sLog%"
			for /f "usebackq tokens=*" %%i in ("%sFileSource%") do (
				echo Processing [%%i]...
				set sName=
				set sAddress=
				set sError=
				set bCriticalError=
				>nul copy nul "%sStdOut%"
				>nul copy nul "%sStdErr%"
				nslookup.exe "%%i" 1>"%sStdOut%" 2>"%sStdErr%"
				<"%sStdErr%" set /p sError=
				if defined sError (
					if "!sError:~0,3!" equ "***" (
						>>"%sLog%" echo %%i = !sError!
						set bCriticalError=1
					)
				)
				if not defined bCriticalError (
					set /a iCount = 0
					for /f "usebackq skip=3 tokens=2 delims=,:	 " %%j in ("%sStdOut%") do (
						set /a iCount += 1
						if !iCount! equ 1 set sName=%%j
						if !iCount! equ 2 set sAddress=%%j
					)
					>>"%sLog%" echo !sName! = !sAddress!
				)
			)
			if exist "%sStdOut%" del /f /q "%sStdOut%"
			if exist "%sStdErr%" del /f /q "%sStdErr%"
		) else (
			echo File with Names list [%sFileSource%] not found
		)
	) else (
		call :Usage
		exit /b 1
	)
) else (
	call :Usage
	exit /b 1
)
endlocal
exit /b 0
rem ==========================================================================
rem ==========================================================================
:Usage
	echo Usage: %~nx0 ^<Names list^> ^<Log file^>
	exit /b 0
rem ==========================================================================
rem ==========================================================================
rem Функция GetTemporaryName()
rem
rem Серый форум / CMD/BAT: генерация пути для временного файла или папки
rem (http://forum.script-coding.com/viewtopic.php?id=6259)
rem ==========================================================================
:GetTemporaryName
	setlocal enableextensions enabledelayedexpansion
:NextName
	set sTempName=%temp%\temp%random%.tmp
	if exist "%sTempName%" goto :NextName
	set sProcName=%~0
	endlocal & set %sProcName:~4%=%sTempName%
	exit /b 0
rem ==========================================================================
Ответить

Вернуться в «Скриптовые языки администрирования Windows»