December 30, 200817 yr Hey all,I am developing a very simple deployment solution. It works well but I'm having some trouble with the return/error codes. When I put a fictitious target computer name in tst.txt, it will return either 0, 53, or 9009 (due to DNS issues on our network). It will return a 0 when it has executed successfully on a real target computer. Here's the source below:@echo offecho ********************** >>errors.txtdate /t >>errors.txttime /t >>errors.txtecho ---------------------- >>errors.txtclsfor /f %%a in (tst.txt) DO (echo Executing on %%aecho ======================PSEXEC %%a -c "C:\deployment tool\dummy.bat" dummy.batecho %%a reported errorlevel: %errorlevel% >> errors.txtecho ======================echo %errorlevel%pause )It reads the names of target machines from tst.txt. Dummy.bat is the script that is to be run on the target machines. And error.txt is of course where the errorlevel is supposed to be recorded.I know that there would be a fair amount of interest in a system like this and hope that we can get this up and running.Thanks in advance! Edited December 31, 200817 yr by robotnik
January 1, 200917 yr Try this...@ECHO OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET TARGETFILE=%~dp0targets.txtSET LOG=%~dpn0.logIF EXIST "!LOG!" DEL /Q "!LOG!"CALL :TEE %DATE: =0%, %TIME: =0%CALL :TEE ~~~~~~~~~~~~~~~~~~~~~~~IF EXIST "%TARGETFILE%" FOR /F "tokens=*" %%C IN ('type "%TARGETFILE%"') DO ( IF "%%~C"=="" GOTO :EOF SET COMMAND=PSEXEC %%~C -c "C:\deployment tool\dummy.bat" dummy.bat CALL :TEE running !COMMAND! CALL !COMMAND! IF NOT !ERRORLEVEL! EQU 0 ( CALL :TEE %%C reported errorlevel: !ERRORLEVEL! ) CALL :TEE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)PAUSEGOTO :EOF:TEE ECHO %* ECHO %* 2>&1 1>>"%LOG%" GOTO :EOFAl
Create an account or sign in to comment