Results 1 to 9 of 9
  1. #1
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a batch file...and log

    I've got the following batch:

    @echo off
    usmc_nfstranspoupdatesw2242.exe /q
    usmc_nfstranspoupdatesw5682.exe /q

    echo %computername% >> usmc_nfstranspoupdatesupdates.txt

    I'd like to add to the text file something that would tell me the success or failure of each update. I use PSEXEC to run batch updates on about 100 computers, and would like to log success/failures of multiple updates. If I were only doing one update, it wouldn't be that big of a deal, but since I'm trying more than one at once, I'm lost.
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What's more, you deserve to be hacked." -Richard Clarke

  2. #2
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a batch file...and log

    <hr>I'd like to add to the text file something that would tell me the success or failure of each update.<hr>
    How would you determine this? Do you get a return code/errorlevel from the update? Or message(s) on the console passed back from the target computer by PSEXEC, which can be inspected for content?

    I'm not sure whether you are doing these updates for one computer, followed by the next, etc, because if you're doing them all 'simultaneously' you might have some trouble with many computers potentially trying to write to the single updates.txt log file simultaneously.

    I presume that you're actually doing something like

    FOR /F %%a IN (list-of-100-computers.txt) DO CALL :UPDATE %%a

    where :UPDATE is a label at the start of a subroutine to do the update for the PC currently being addressed. I use this technique extensively at work...

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  3. #3
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a batch file...and log

    I have a list of IPs on my c drive...I use this line:

    psexec @c:computers.txt -u naeusmcsa.usmc -c usmc_nfstranspoupdatesupdates.bat


    It connects to each computer one at a time, runs all the updates in the batch, and then moves on to the next computer. The text file changes when I receive vulnerability scans, I add or remove computers as necessary...
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  4. #4
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a batch file...and log

    That's another way of doing it. But you still haven't said what you get back as console message(s) from each update!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  5. #5
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a batch file...and log

    Here's roughly what I would do -- it will do a starting timestamp, write all messages for that update, then do an ending timestamp.<pre>@echo off
    setlocal
    set updpath=usmc_nfstranspoupdates
    set log=%updpath%updates.txt

    :: one way of plugging the update numbers in; FOR /F probably better!
    for %%a in (2242 5682) do call :update %%a

    endlocal
    goto :eof
    :: ------------------------------------------------------------------

    :update implement the passed update number for the current PC
    set updno=%1
    echo %computername% %date% %time:~0,8% update %updno% started >> %log%
    %updpath%w%updno%.exe /q >> %log%
    echo %computername% %date% %time:~0,8% update %updno% ended >> %log%
    goto :eof
    </pre>

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  6. #6
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a batch file...and log

    John,

    Could you point me to a site that you'd recommend for learning how to create a batch file?
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  7. #7
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a batch file...and log

    I would actually recommend about twenty years experience!

    There are many hits found from Googling for "DOS batch techniques"...

    Try William and Linda Allen for a set of lessons. Jump in at whatever level.
    And download <A target="_blank" HREF=ftp://garbo.uwasa.fi/pc/link/tscmd.zip>TSCMD</A>, examples of BATch techniques by Prof Timo Salmi.
    Ritchie Lawrence's Batch Function Library (especially the Date and Time functions) are brilliant, if quite hard to understand.

    It's a good move to save or print out all the help information found from doing Start -> Run on
    %windir%hh.exe mk:@MSITStore:%windir%helpntcmds.chm::/ntcmds.htm
    and clicking on "Batch Files".
    An alternative is to do IF /?, START /?, SET /?, CALL /?, and all the rest of the DOS commands to get the Help information.

    The Google (usenet?) group http://groups.google.co.uk/group/alt.msdos.batch.nt answers technical questions, but can be a bit stroppy...!

    I can send you some of my BATch file examples, if you're feeling masochistic!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  8. #8
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a batch file...and log

    >> if you're feeling masochistic!

    I'm in the Marine Corps...need I say more? I'll pm you my email if you'd be so kind to send them.
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  9. #9
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a batch file...and log

    I think it would benefit everyone to keep it on the public boards. Perhaps John can zip a few up and attach the ZIP file?
    -Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •