Howto make a batch that will read a .txt file as input

Discussion in 'Scripting' started by David Lewis, Oct 17, 2003.

  1. David Lewis

    David Lewis Guest

    I want to use a batch file to copy/install stuff to remote machines.
    I want to have a text file with a list of machines to process as input
    to the batch. When the batch file runs it processes every machine
    in the list.

    Or maybe how do I have a batch process every machine in the domain
    except servers? That is needed also, as I have two different kinds of
    updates to deploy. OS updates to all machines and Software updates to
    specific machines.

    Last how could I check for OS versions. I might need to process NT
    different then Win2000
     
    David Lewis, Oct 17, 2003
    #1
    1. Advertisements

  2. Here's how we process similar batch files:

    we create 2 batch files: one calls the other

    in the 1st one, it contains the command variables you want executed.
    example: (filename is auto.bat)
    rcmd \\%1 net stop spooler

    in the 2nd file, it contains the list of servers\machines. example:
    (filename is serverlist.bat (or whatever name))
    call auto.bat server-name-here
    call auto.bat server-name-here

    The 2nd file is editable in an excel spreadsheet as needed and then
    copy\pasted into this txt file and renamed to bat (or just directly to the
    bat file.)

    Thanks-
    Richard
     
    Richard Moreno, Oct 17, 2003
    #2
    1. Advertisements

  3. David Lewis

    Mike Guest

    ::~~Script~~.
    :: @echo off
    ::----------------------- batch code -----------------------

    ::variables
    :: sets initial variables

    :mainloop
    :: Loops through a file for server names
    for /F %%I in (c:\temp\server.txt) do Call :begin %%I
    goto :EOF

    :begin
    set srv=%1
    :do the deed
    : copys a file to the C:\Temp directory on a distant machine
    xcopy c:\temp\myfile.exe \\%srv%\c$\temp
    :exit
     
    Mike, Oct 20, 2003
    #3
  4. David Lewis

    David Lewis Guest

    thankx

    "Mike" <>
    |>
    |>::~~Script~~.
    |>:: @echo off
    |>::----------------------- batch code -----------------------
    |>
    |>::variables
    |>:: sets initial variables
    |>
    |>:mainloop
    |>:: Loops through a file for server names
    |>for /F %%I in (c:\temp\server.txt) do Call :begin %%I
    |>goto :EOF
    |>
    |>:begin
    |>set srv=%1
    |>:do the deed
    |>: copys a file to the C:\Temp directory on a distant machine
    |>xcopy c:\temp\myfile.exe \\%srv%\c$\temp
    |>:exit
     
    David Lewis, Nov 4, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.