• Creating a batch file…and log

    Home » Forums » AskWoody support » Windows » Windows – other » Creating a batch file…and log

    Author
    Topic
    #436164

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #1033174

      [indent]


      I’d like to add to the text file something that would tell me the success or failure of each update.


      [/indent]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

      • #1033188

        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…

        • #1033200

          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

          • #1033202

            Here’s roughly what I would do — it will do a starting timestamp, write all messages for that update, then do an ending timestamp.

            @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

            John

            • #1033226

              John,

              Could you point me to a site that you’d recommend for learning how to create a batch file?

            • #1033237

              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 TSCMD, 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%5B/url%5D 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

            • #1033336

              >> 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.

            • #1033547

              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?

    Viewing 0 reply threads
    Reply To: Creating a batch file…and log

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: