Again with Parallel Process
Moderator: DosItHelp
Again with Parallel Process
I found this in Parallel process Code form googlling the start process at the same time in same window... like ping few ip's at the same time form same window...
i have ipadd.csv user.txt pass.txt i have try lot to do that it start psexec.exe in parallel process. but not able to solve.
there is options there but i can't work out i don't wan't ping option just psexec.exe option..
Pls help with this.
Code:-
@echo off
setlocal enableDelayedExpansion
:: Display the output of each process if the /O option is used
:: else ignore the output of each process
if /i "%~1" equ "/O" (
set "lockHandle=1"
set "showOutput=1"
) else (
set "lockHandle=1^>nul 9"
set "showOutput="
)
:: List of commands goes here. Each command is prefixed with :::
::: ping /n 05 ::1
::: ping /n 20 ::1
::: ping /n 10 ::1
::: ping /n 15 ::1
::: ping /n 07 ::1
::: ping /n 05 ::1
::: ping /n 20 ::1
::: ping /n 10 ::1
::: ping /n 15 ::1
::: ping /n 07 ::1
:: Define the maximum number of parallel processes to run.
:: Each process number can optionally be assigned to a particular server
:: and/or cpu via psexec specs (untested).
set "maxProc=4"
:: Optional - Define CPU targets in terms of PSEXEC specs
:: (everything but the command)
::
:: If a cpu is not defined for a proc, then it will be run on the local machine.
:: I haven't tested this feature, but it seems like it should work.
::
:: set cpu1=psexec \\server1 ...
:: set cpu2=psexec \\server1 ...
:: set cpu3=psexec \\server2 ...
:: etc.
:: For this demo force all cpu specs to undefined (local machine)
for /l %%N in (1 1 %maxProc%) do set "cpu%%N="
:: Get a unique base lock name for this particular instantiation.
:: Incorporate a timestamp from WMIC if possible, but don't fail if
:: WMIC not available. Also incorporate a random number.
set "lock="
for /f "skip=1 delims=-+ " %%T in ('2^>nul wmic os get localdatetime') do (
set "lock=%%T"
goto :break
)
:break
set "lock=%temp%\lock%lock%_%random%_"
:: Initialize the counters
set /a "startCount=0, endCount=0"
:: Clear any existing end flags
for /l %%N in (1 1 %maxProc%) do set "endProc%%N="
:: Launch the commands in a loop
set launch=1
for /f "tokens=* delims=:" %%A in ('findstr /b ":::" "%~f0"') do (
if !startCount! lss %maxProc% (
set /a "startCount+=1, nextProc=startCount"
) else (
call :wait
)
set cmd!nextProc!=%%A
if defined showOutput echo -------------------------------------------------------------------------------
echo !time! - proc!nextProc!: starting %%A
2>nul del %lock%!nextProc!
%= Redirect the lock handle to the lock file. The CMD process will =%
%= maintain an exclusive lock on the lock file until the process ends. =%
start /b "" cmd /c %lockHandle%^>"%lock%!nextProc!" 2^>^&1 !cpu%%N! %%A
)
set "launch="
:wait
:: Wait for procs to finish in a loop
:: If still launching then return as soon as a proc ends
:: else wait for all procs to finish
:: redirect stderr to null to suppress any error message if redirection
:: within the loop fails.
for /l %%N in (1 1 %startCount%) do (
%= Redirect an unused file handle to the lock file. If the process is =%
%= still running then redirection will fail and the IF body will not run =%
if not defined endProc%%N if exist "%lock%%%N" (
%= Made it inside the IF body so the process must have finished =%
if defined showOutput echo ===============================================================================
echo !time! - proc%%N: finished !cmd%%N!
if defined showOutput type "%lock%%%N"
if defined launch (
set nextProc=%%N
exit /b
)
set /a "endCount+=1, endProc%%N=1"
) 9>>"%lock%%%N"
) 2>nul
if %endCount% lss %startCount% (
1>nul 2>nul ping /n 2 ::1
goto :wait
)
2>nul del %lock%*
if defined showOutput echo ===============================================================================
echo Thats all folks!
Output:-
12:24:07.52 - proc1: starting ping /n 05 ::1
12:24:07.52 - proc2: starting ping /n 20 ::1
12:24:07.53 - proc3: starting ping /n 10 ::1
12:24:07.54 - proc4: starting ping /n 15 ::1
12:24:11.60 - proc1: finished ping /n 05 ::1
12:24:11.60 - proc1: starting ping /n 07 ::1
12:24:16.66 - proc3: finished ping /n 10 ::1
12:24:16.66 - proc3: starting ping /n 05 ::1
12:24:17.68 - proc1: finished ping /n 07 ::1
12:24:17.68 - proc1: starting ping /n 20 ::1
12:24:20.72 - proc3: finished ping /n 05 ::1
12:24:20.72 - proc3: starting ping /n 10 ::1
12:24:21.75 - proc4: finished ping /n 15 ::1
12:24:21.75 - proc4: starting ping /n 15 ::1
12:24:26.82 - proc2: finished ping /n 20 ::1
12:24:26.82 - proc2: starting ping /n 07 ::1
12:24:29.86 - proc3: finished ping /n 10 ::1
12:24:32.89 - proc2: finished ping /n 07 ::1
12:24:35.92 - proc4: finished ping /n 15 ::1
12:24:36.93 - proc1: finished ping /n 20 ::1
Thats all folks
i have ipadd.csv user.txt pass.txt i have try lot to do that it start psexec.exe in parallel process. but not able to solve.
there is options there but i can't work out i don't wan't ping option just psexec.exe option..
Pls help with this.
Code:-
@echo off
setlocal enableDelayedExpansion
:: Display the output of each process if the /O option is used
:: else ignore the output of each process
if /i "%~1" equ "/O" (
set "lockHandle=1"
set "showOutput=1"
) else (
set "lockHandle=1^>nul 9"
set "showOutput="
)
:: List of commands goes here. Each command is prefixed with :::
::: ping /n 05 ::1
::: ping /n 20 ::1
::: ping /n 10 ::1
::: ping /n 15 ::1
::: ping /n 07 ::1
::: ping /n 05 ::1
::: ping /n 20 ::1
::: ping /n 10 ::1
::: ping /n 15 ::1
::: ping /n 07 ::1
:: Define the maximum number of parallel processes to run.
:: Each process number can optionally be assigned to a particular server
:: and/or cpu via psexec specs (untested).
set "maxProc=4"
:: Optional - Define CPU targets in terms of PSEXEC specs
:: (everything but the command)
::
:: If a cpu is not defined for a proc, then it will be run on the local machine.
:: I haven't tested this feature, but it seems like it should work.
::
:: set cpu1=psexec \\server1 ...
:: set cpu2=psexec \\server1 ...
:: set cpu3=psexec \\server2 ...
:: etc.
:: For this demo force all cpu specs to undefined (local machine)
for /l %%N in (1 1 %maxProc%) do set "cpu%%N="
:: Get a unique base lock name for this particular instantiation.
:: Incorporate a timestamp from WMIC if possible, but don't fail if
:: WMIC not available. Also incorporate a random number.
set "lock="
for /f "skip=1 delims=-+ " %%T in ('2^>nul wmic os get localdatetime') do (
set "lock=%%T"
goto :break
)
:break
set "lock=%temp%\lock%lock%_%random%_"
:: Initialize the counters
set /a "startCount=0, endCount=0"
:: Clear any existing end flags
for /l %%N in (1 1 %maxProc%) do set "endProc%%N="
:: Launch the commands in a loop
set launch=1
for /f "tokens=* delims=:" %%A in ('findstr /b ":::" "%~f0"') do (
if !startCount! lss %maxProc% (
set /a "startCount+=1, nextProc=startCount"
) else (
call :wait
)
set cmd!nextProc!=%%A
if defined showOutput echo -------------------------------------------------------------------------------
echo !time! - proc!nextProc!: starting %%A
2>nul del %lock%!nextProc!
%= Redirect the lock handle to the lock file. The CMD process will =%
%= maintain an exclusive lock on the lock file until the process ends. =%
start /b "" cmd /c %lockHandle%^>"%lock%!nextProc!" 2^>^&1 !cpu%%N! %%A
)
set "launch="
:wait
:: Wait for procs to finish in a loop
:: If still launching then return as soon as a proc ends
:: else wait for all procs to finish
:: redirect stderr to null to suppress any error message if redirection
:: within the loop fails.
for /l %%N in (1 1 %startCount%) do (
%= Redirect an unused file handle to the lock file. If the process is =%
%= still running then redirection will fail and the IF body will not run =%
if not defined endProc%%N if exist "%lock%%%N" (
%= Made it inside the IF body so the process must have finished =%
if defined showOutput echo ===============================================================================
echo !time! - proc%%N: finished !cmd%%N!
if defined showOutput type "%lock%%%N"
if defined launch (
set nextProc=%%N
exit /b
)
set /a "endCount+=1, endProc%%N=1"
) 9>>"%lock%%%N"
) 2>nul
if %endCount% lss %startCount% (
1>nul 2>nul ping /n 2 ::1
goto :wait
)
2>nul del %lock%*
if defined showOutput echo ===============================================================================
echo Thats all folks!
Output:-
12:24:07.52 - proc1: starting ping /n 05 ::1
12:24:07.52 - proc2: starting ping /n 20 ::1
12:24:07.53 - proc3: starting ping /n 10 ::1
12:24:07.54 - proc4: starting ping /n 15 ::1
12:24:11.60 - proc1: finished ping /n 05 ::1
12:24:11.60 - proc1: starting ping /n 07 ::1
12:24:16.66 - proc3: finished ping /n 10 ::1
12:24:16.66 - proc3: starting ping /n 05 ::1
12:24:17.68 - proc1: finished ping /n 07 ::1
12:24:17.68 - proc1: starting ping /n 20 ::1
12:24:20.72 - proc3: finished ping /n 05 ::1
12:24:20.72 - proc3: starting ping /n 10 ::1
12:24:21.75 - proc4: finished ping /n 15 ::1
12:24:21.75 - proc4: starting ping /n 15 ::1
12:24:26.82 - proc2: finished ping /n 20 ::1
12:24:26.82 - proc2: starting ping /n 07 ::1
12:24:29.86 - proc3: finished ping /n 10 ::1
12:24:32.89 - proc2: finished ping /n 07 ::1
12:24:35.92 - proc4: finished ping /n 15 ::1
12:24:36.93 - proc1: finished ping /n 20 ::1
Thats all folks
Re: Again with Parallel Process
@foxidrive yes bro bcoz it start lot's of cmd.exe so.
PLEASE you help with this code ....
PLEASE you help with this code ....
Re: Again with Parallel Process
What is the task? I read that you want to start 20 PSEXEC processes off at the one time to install Java and other things, is that right?
Of course it is going to launch 20 processes - that's what you want to do...
What problems do you have with the code that abc0502 wrote?
Of course it is going to launch 20 processes - that's what you want to do...
What problems do you have with the code that abc0502 wrote?
Re: Again with Parallel Process
Hi, I remembered that i have this vbscript, it enable you to run batch files hidden, you won't see the window of the cmd but if you open task manager, you will see there process.
here, change the location to your batch location
if the location has spaces replace the 2nd line with
number 0 in the 3rd line:
0 for hidden mode and 7 for minimized mode
the batch will be running in the background but in this case you won't see any output or know if any errors happened unless you change your code to create a log file after it finish so you can review it later
here, change the location to your batch location
Code: Select all
Set oShell = CreateObject("WSCript.shell")
sCmd = "C:\yourbatchfile.bat"
oShell.Run sCmd, 0, False
if the location has spaces replace the 2nd line with
Code: Select all
sCmd = Chr(34) & "%userprofile%\desktop\batch.bat" & Chr(34)
number 0 in the 3rd line:
0 for hidden mode and 7 for minimized mode
the batch will be running in the background but in this case you won't see any output or know if any errors happened unless you change your code to create a log file after it finish so you can review it later
Re: Again with Parallel Process
Dear @foxidrive
This all i try to do that i want parallel process & up code is able to do..
it start ping process at same time in 4 computer it depend on you system capacity load.
so i WANT start java with psexec .
for that i have ipadd.csv user.txt pass.txt i have to start java at time like ping....
This all i try to do that i want parallel process & up code is able to do..
it start ping process at same time in 4 computer it depend on you system capacity load.
so i WANT start java with psexec .
for that i have ipadd.csv user.txt pass.txt i have to start java at time like ping....
Re: Again with Parallel Process
How many machines do you have in your set? Do they all share the same admin username and password?
Re: Again with Parallel Process
i have total 150 ps's with 5 lab with 30 pc's per lab.
For username & password i have 3 set.
like:- administrator 123456
adminlab3 852369
adminlab5 741258
For username & password i have 3 set.
like:- administrator 123456
adminlab3 852369
adminlab5 741258
Re: Again with Parallel Process
Ok. Now what will happen if you start 30 PSexec sessions at once? Do one lab at a time.
Is there a problem doing it that way?
Is there a problem doing it that way?
Re: Again with Parallel Process
when i start session it will done one by one.. & if it stuck at any place like in 5 number machine have problem
whole session just stuck..
now i want start psexec in 30 pc's at same time upstage code is start ping in 5 computer at same time with same window. so if 3 number is timeout it don't matter...
whole session just stuck..
now i want start psexec in 30 pc's at same time upstage code is start ping in 5 computer at same time with same window. so if 3 number is timeout it don't matter...
Re: Again with Parallel Process
Create a file called lab1.txt with this format, one for each lab:
ipaddress1:username:password
ipaddress2:username:password
ipaddress3:username:password
ipaddress4:username:password
...
ipaddress30:username:password
And then use abc0502's code to run the process on the entire lab. If you want to you can make the file with only 15 machines at once.
Repeat for each lab and change the txt file.
The benefit here is that you will be able to modify the batch file easily.
ipaddress1:username:password
ipaddress2:username:password
ipaddress3:username:password
ipaddress4:username:password
...
ipaddress30:username:password
And then use abc0502's code to run the process on the entire lab. If you want to you can make the file with only 15 machines at once.
Repeat for each lab and change the txt file.
The benefit here is that you will be able to modify the batch file easily.
Code: Select all
@echo off & cls
For /F "tokens=1,2,3 delims=:" %%A in ('type "lab1.txt"') Do (
start /min "%%A" psexec \\%%A -%%B -%%C -c java.exe /qn"
)
pause