robotnik Posted December 30, 2008 Share Posted December 30, 2008 (edited) 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, 2008 by robotnik Link to comment Share on other sites More sharing options...
AlBundy33 Posted January 1, 2009 Share Posted January 1, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now