Jump to content

Oh soooo close....


robotnik

Recommended Posts

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 off
echo ********************** >>errors.txt
date /t >>errors.txt
time /t >>errors.txt
echo ---------------------- >>errors.txt
cls
for /f %%a in (tst.txt) DO (
echo Executing on %%a
echo ======================
PSEXEC %%a -c "C:\deployment tool\dummy.bat" dummy.bat
echo %%a reported errorlevel: %errorlevel% >> errors.txt
echo ======================
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 by robotnik
Link to comment
Share on other sites


Try this...

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET TARGETFILE=%~dp0targets.txt
SET LOG=%~dpn0.log

IF 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)
PAUSE
GOTO :EOF

:TEE
ECHO %*
ECHO %* 2>&1 1>>"%LOG%"
GOTO :EOF

Al

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...