@ECHO OFF GOTO BEGIN Author: Kyle Dooley 1/15/2008 Comments: Master Logon script for PBGC. Instructions: 1. This scripts purpose is to Throttle spawned scripts 2. Set your number of script at precount. It will spawn that number os scripts and wait unti one closed before lauching the next. 3. This version takes :BEGIN ::Run the AsyncScripts REM During this script, ensure the path it runs from is searched when looking for needed files SET SCRIPTPATH=%~p0 CD %SCRIPTPATH% REM Set FILEDATE to current date in format yyyymmdd and FILETIME to current time in format= hhmm set FileDate=%date:~6,4%%date:~0,2%%date:~3,2% set FileTime=%time:~0,2%%time:~3,2% if not exist %SCRIPTPATH%\INSTALL\. MD %SCRIPTPATH%\INSTALL ECHO.>>%SCRIPTPATH%\INSTALL\NMAPresults.csv ECHO Usage: ECHO Enter name of text file with nodes, IP ranges, etc. If none specified, ECHO then filename "SERVERS.TXT" will be assumed: SET /p FILE= IF "%FILE%"=="" SET FILE=SERVERS.TXT IF NOT EXIST %FILE% ECHO No such FILE! Exiting now! & GOTO :END ECHO FILE,%FILE%>>%SCRIPTPATH%\INSTALL\NMAPresults.csv REM Update NMAP log file w/current Date and Time, and begin work for each host ECHO LISTBEGIN,%DATE% %TIME% >>%SCRIPTPATH%\INSTALL\NMAPresults.csv SET /A CNT=0 SET /A PRECOUNT=5 SET /A COUNT=0 REM Find the number of preexisting instaces of CSCRIPT (or CMD) for this user. echo Checking For Running Scripts FOR /F "tokens=1*" %%G in ('tasklist /NH /FI "IMAGENAME eq CMD.exe " /FI "USERNAME eq %username%"') Do Call :PRECountCSCRIPT :AsyncScripts ::Put your command line here for /f %%e in (%file%) do Call :runSub %%e REM Initiate search of subnet for OS and count them by type REM **SOME ACTION TBD** ECHO LISTEND,%DATE% %TIME% >>%SCRIPTPATH%\INSTALL\NMAPresults.csv echo. echo %RANGE% ECHO %RANGE%,STARTED>> %SCRIPTPATH%\INSTALL\NMAPresults.csv GOTO MONITORSCRIPTS :runSub SET SUBNET=%1 echo. echo %SUBNET% >>NMAPparse.csv START "NMAPWINstart-tcp02 %SUBNET%" /MIN NMAPWINstart-tcp02.bat %SUBNET% REM Take any CIDR off %IPSUBNET% for filename below for /f "tokens=1-2 delims=/" %%I in ("%SUBNET%") do set SUBNETFILE=%%I ECHO %SUBNETFILE% REM Next line is for testing if needed REM START "TEST-TEST %1" /MIN test2.bat %1 echo "NMAPWINstart-tcp02.bat" started in external window! ECHO %SUBNET%,STARTED>> NMAPparse.csv rem GOTO :EOF :MONITORSCRIPTS REM This section monitors the various scripts running. If there are none running it moves on SET /A COUNT=%count% + 1 SLEEP 3 echo waiting for subscripts to finish... SET /A cnt=0 FOR /F "tokens=1*" %%G in ('tasklist /NH /FI "IMAGENAME eq CMD.exe " /FI "USERNAME eq %username%"') Do call :CountCSCRIPT REM if the number os scripts running is <= The number we started with go to end IF %cnt% LEQ %PRECOUNT% GOTO :EOF GOTO Monitorscripts echo %count% Seconds to run Aysync Scripts sleep 1 GOTO :EOF :CountCSCRIPT REM Counts the number of scripts currently running. SET /A cnt=%cnt% + 1 GOTO :EOF :PRECountCSCRIPT REM counts the number of scripts running before we launch any of ours. SET /A PRECOUNT=%PRECOUNT% + 1 GOTO :EOF ECHO LISTEND,%DATE% %TIME% >>%SCRIPTPATH%\INSTALL\NMAPresults.csv goto :EOF :END