Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pause or wait with batch script to process all information

Status
Not open for further replies.

n3tw0rkadm1n1strat0r

IS-IT--Management
Aug 29, 2006
119
US
Does anyone know how to make batch files wait after they have processes information...for example, it would wait to process all the information, write that info to a text file, and then send and email. The problem I am running into is that it only writes part of the data to a text file, not waiting till that part of the script is done and going straight to sending an email. Here's my script, thanks to anyone who can help.

Code:
@ECHO OFF
TITLE Website Check

REM -----------------------------------
REM

SET MachineList=MachineList.txt
SET ResultsFile=Results.txt

REM
REM -----------------------------------

CLS
ECHO.
IF NOT EXIST "%MachineList%" (
ECHO Cannot locate Machine List: %MachineList%
PAUSE>NUL
GOTO :EOF
)

ECHO Processing all machine names in %MachineList% . . .
ECHO.

FOR /f "tokens=*" %%M in (%MachineList%) do CALL :CHECK "%%M"

GOTO :EOF

:CHECK
SET Machine=%~1
SET Machine=%Machine: =%

PING -n 1 -w 1000 %Machine%>NUL
IF %ERRORLEVEL% NEQ 0 ECHO %Machine% did not respond at %Time%>>%ResultsFile%

CSCRIPT.EXE SENDMAIL.VBS -?

EXIT /B

:EOF

I have tried the sleep and pause command and those both do not work...
 
You could split up the processes into two batch files.
Bat file 1 would be all the lines above except
cscript email.vbs
bat file two would contains something like
if exist sonmething call cscript email.vbs.

so a bat file lets say one.bat looks like the following.

call bat file 1
call bat file 2

the call command says wait till bat file 1 is done
then call bat file 2.

Hope this helps you
 
I'm not sure that I understand how to do this...I would take out the "CSCRIPT.EXE SENDMAIL.VBS -?" and then make another batch script that will call run when the first one is done...but how would it know that the first one is done?
 
There are three .bat files a, b, and c.
you run a
a calls b
then
a calls c

b contains all the code but the running of cscript
c calls cscript

When you CALL a batch file it suspends processing
until the called .bat file exits.

Bob
 
Putting cscript after EOF didn't work...I tried the other way too but I dont think I have it set up right. At the end of my script I would put:

CALL SENDMAIL.bat

And then in that batch file I would put:

cscript SENDMAIL.vbs

Will that work?
 
Yes, That should work.
The reason the :Eof thing does not work
is that :EOF when used as a goto tag
causes an imediate exit and not a branch to a :Tag.
If you change :EOF to :anything it should work

Bob
 
Sorry I have one more question, what command would I use if I wanted the text file that I have the information writing to, to overwrite itself everytime the script runs?
 
At the very beginning of the script use this assuming your file is named file.txt

IF EXIST FILE.TXT DEL FILE.TXT

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top