Convert multiple line file to one line

M

MordacNM

Is it possible to take a list of 1000+ machine names (pc-1234, etc.) that
appear in a text file (one to a line) process (via batch) 25 at a time then
go on to the next group of 25.

My current batch file processes one machine at a time and I'd like it to
use the START cmd to open 25 instances of another batch file that does
robocopy and psexec then exits. I'd like to limit the number of cmd
windows open at a time since the commands that run from the other batch
will keep my machine rather busy with file copying.

I've thought about somehow using the "tokens=m-n" option in the FOR command
but there doesn't seem to be an (obvious) way to process a limited number
at any one time.

Thanks
 
P

Phil Robyn

MordacNM said:
Is it possible to take a list of 1000+ machine names (pc-1234, etc.) that
appear in a text file (one to a line) process (via batch) 25 at a time then
go on to the next group of 25.

My current batch file processes one machine at a time and I'd like it to
use the START cmd to open 25 instances of another batch file that does
robocopy and psexec then exits. I'd like to limit the number of cmd
windows open at a time since the commands that run from the other batch
will keep my machine rather busy with file copying.

I've thought about somehow using the "tokens=m-n" option in the FOR command
but there doesn't seem to be an (obvious) way to process a limited number
at any one time.

Thanks

I tried this with a list of 700 machine names; see if it will work for you.

=====begin C:\cmd\demo\MultiSpawn.cmd ====================
01. @echo off
02. setlocal
03. set ctr=0
04. for /f "tokens=1" %%a in (c:\temp\machines.txt) do call :main %%a
05.
06. :main
07. set /a ctr+=1
08. set computers=%computers% %1
09. if %ctr% EQU 25 (
10. echo start "" batchfiletwo %computers%
11. set /a ctr=0
12. set computers=
13. )
14. goto :EOF
=====end C:\cmd\demo\MultiSpawn.cmd ====================
 
M

MordacNM

I tried this with a list of 700 machine names; see if it will work for
you.

=====begin C:\cmd\demo\MultiSpawn.cmd ====================
01. @echo off
02. setlocal
03. set ctr=0
04. for /f "tokens=1" %%a in (c:\temp\machines.txt) do call :main %%a
05.
06. :main
07. set /a ctr+=1
08. set computers=%computers% %1
09. if %ctr% EQU 25 (
10. echo start "" batchfiletwo %computers%
11. set /a ctr=0
12. set computers=
13. )
14. goto :EOF
=====end C:\cmd\demo\MultiSpawn.cmd ====================

Phil - Thanks for the prompt reply.

However, when I run the code as shown (editing for path and batchfiletwo
and removing the echo on line 10), it appears that it's parsing thru the
list of machines until it gets 25 machine names, then passes all 25
machine names to the 2nd batch all at once - on one cmd line. I tested
on a list with 81 machines. I got three cmd windows open (the 2nd batch
file simply echoes the machine name and pauses) with the name of the 2nd
batch plus all 25 machine names listed after it in the title bar.

What I'm after is to pass one machine name to the 2nd batch file at a
time, opening 25 instances of the 2nd batch file then going on to the
next 25 after they're done.

My 2nd batch will contain the actual commands I'm needing to run against
each machine in the list. It'll run a robocopy routine, psexec to start
the remote process, then logs some info into a remote log file with an
echo command and exits.

Ideally, I'd like to have it continually processing the list until it
reaches the end of the list - having no more than 25 active cmd windows
open at a time.

Thanks
 
J

Jerold Schulman

Phil - Thanks for the prompt reply.

However, when I run the code as shown (editing for path and batchfiletwo
and removing the echo on line 10), it appears that it's parsing thru the
list of machines until it gets 25 machine names, then passes all 25
machine names to the 2nd batch all at once - on one cmd line. I tested
on a list with 81 machines. I got three cmd windows open (the 2nd batch
file simply echoes the machine name and pauses) with the name of the 2nd
batch plus all 25 machine names listed after it in the title bar.

What I'm after is to pass one machine name to the 2nd batch file at a
time, opening 25 instances of the 2nd batch file then going on to the
next 25 after they're done.

My 2nd batch will contain the actual commands I'm needing to run against
each machine in the list. It'll run a robocopy routine, psexec to start
the remote process, then logs some info into a remote log file with an
echo command and exits.

Ideally, I'd like to have it continually processing the list until it
reaches the end of the list - having no more than 25 active cmd windows
open at a time.

Thanks

@echo off
setlocal
set /a ctr=0
for /f "tokens=1" %%a in (c:\temp\machines.txt) do set computer=%%a&call :main
endlocal
goto :EOF
:main
:: Sleep 2 seconds
@ping -n 3 127.0.0.1>nul
set /a ctr+=1
if %ctr% LSS 24 goto submit
start "" /wait batchfiletwo %computer%
set /a ctr=0
:: wait 1 extra minute
@ping -n 61 127.0.0.1>nul
goto :EOF
:submit
start "" batchfiletwo %computer%

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
J

Jerold Schulman

Phil - Thanks for the prompt reply.

However, when I run the code as shown (editing for path and batchfiletwo
and removing the echo on line 10), it appears that it's parsing thru the
list of machines until it gets 25 machine names, then passes all 25
machine names to the 2nd batch all at once - on one cmd line. I tested
on a list with 81 machines. I got three cmd windows open (the 2nd batch
file simply echoes the machine name and pauses) with the name of the 2nd
batch plus all 25 machine names listed after it in the title bar.

What I'm after is to pass one machine name to the 2nd batch file at a
time, opening 25 instances of the 2nd batch file then going on to the
next 25 after they're done.

My 2nd batch will contain the actual commands I'm needing to run against
each machine in the list. It'll run a robocopy routine, psexec to start
the remote process, then logs some info into a remote log file with an
echo command and exits.

Ideally, I'd like to have it continually processing the list until it
reaches the end of the list - having no more than 25 active cmd windows
open at a time.

Thanks

** ammended **

@echo off
setlocal
set /a ctr=0
for /f "tokens=1" %%a in (c:\temp\machines.txt) do set computer=%%a&call :main
endlocal
goto :EOF
:main
:: Sleep 2 seconds
@ping -n 3 127.0.0.1>nul
set /a ctr+=1
if %ctr% LSS 25 goto submit
start "" /wait batchfiletwo %computer%
set /a ctr=0
:: wait 1 extra minute
@ping -n 61 127.0.0.1>nul
goto :EOF
:submit
start "" batchfiletwo %computer%


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
P

Phil Robyn

MordacNM said:
Phil - Thanks for the prompt reply.

However, when I run the code as shown (editing for path and batchfiletwo
and removing the echo on line 10), it appears that it's parsing thru the
list of machines until it gets 25 machine names, then passes all 25
machine names to the 2nd batch all at once - on one cmd line. I tested
on a list with 81 machines. I got three cmd windows open (the 2nd batch
file simply echoes the machine name and pauses) with the name of the 2nd
batch plus all 25 machine names listed after it in the title bar.

What I'm after is to pass one machine name to the 2nd batch file at a
time, opening 25 instances of the 2nd batch file then going on to the
next 25 after they're done.

My 2nd batch will contain the actual commands I'm needing to run against
each machine in the list. It'll run a robocopy routine, psexec to start
the remote process, then logs some info into a remote log file with an
echo command and exits.

Ideally, I'd like to have it continually processing the list until it
reaches the end of the list - having no more than 25 active cmd windows
open at a time.

Thanks

=====begin C:\cmd\demo\MultiSpawn.cmd ====================
01. @echo off
02. setlocal
03. set ctr=0
04. for /f "tokens=1" %%a in (c:\temp\machines.txt) do call :main %%a
05.
06. :main
07. set /a ctr+=1
08. set computers=%computers% %1
09. if %ctr% EQU 25 (
10. start "" %comspec% /c c:\cmd\demo\batchfiletwo %computers%
11. set /a ctr=0
12. set computers=
13. )
14. goto :EOF
=====end C:\cmd\demo\MultiSpawn.cmd ====================

=====begin C:\cmd\demo\batchfiletwo.cmd ====================
1. @echo off
2. setlocal
3. for %%a in (%*) do (
4. echo %%a
5. echo robocopy ....
6. echo psexec ....
7. wait 1
8. )
9. cls&exit
=====end C:\cmd\demo\batchfiletwo.cmd ====================
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top