1.

Solve : Is there a way to loop through a set of commands and send an email after each?

Answer» HELLO All,
I have this batch file with the following commands. All commands are executed in sequential order from the "push" directory.  This batch file is called in another batch file. I need to send out an email after each "call" command completed. I used the "GOTO" command to jump to the ":MailSend" section  and send out the email. However, I  don't know how to get  back to the "pushd" directory and execute the next "call" command.

I would really appreciate your help.   

Also, if anyone can help me construct  a "FOR" loop to iterate to the "call" commands instead of having to write them 3 times in the file. For example, I LIST the first  "call" command three times  because I want to run it 3 times. I would like to only write it once and loop 3 times or more .

I look forward to getting reply from anyone who can assist with these.

Thanks....

ECHO ON

pushd D:\Program Files\XXX\zzzShared\plugins\com.yy.aa.test.lt.cmdlineexecute_7.2.0.v200803051948


call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig.txt"
call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig.txt"
call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig.txt"

echo Three 15 minutes for 15 users  runs completed.


call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig1S.txt"
call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig1S.txt"

echo Two 2 hours for 40 users runs completed.


call cmdline -configfile "%USERPROFILE%\dirx\SchedConfigMS.txt"
call cmdline -configfile "%USERPROFILE%\dirx\SchedConfigMS.txt"

echo Two 2 hours run with 4 stages completed.


call cmdline -configfile "%USERPROFILE%\\dirX\SchedConfigLR.txt"

echo Twelve hours long duration for 40 users run completed.


echo A total of 8 runs completed.


popd

echo DONE !!!


:MailSend
popd
mailsend1.15b5.exe -smtp server  -l "emailaddressfile.txt" -f fromtoemail -sub "Subject" < "msgfilel.txt"


:End
popd
ECHO Run #1 completed.

i dunno if this will work but you can make another file with
Code: [SELECT]mailsend1.15b5.exe -smtp server  -l "emailaddressfile.txt" -f fromtoemail -sub "Subject" < "msgfilel.txt"

and in your code add

Code: [Select]call thisfile.bat
and for for loop

Code: [Select]for /L %%a in (1,1,3) do (
call cmdline -configfile "%USERPROFILE%\dirx\SchedConfig.txt"
if %%a equ 3 goto A
)Hello devcom,
Thanks for the quick response.  You're awesome!!!!!!!!!!!!!!!!!!!!
I took your suggestions and modified my script, it worked beautifully.

Added the email code to a file call "MailSend.bat" and call it in the script

Code: [Select]mailsend1.15b5.exe -smtp servername  -l ".\XXDIR\EmailAddressfile.txt" -f fromemailaddress -sub "subject text" < ".\XXDIR\mesgfile.txt"
pushd D:\Program Files\XX
Pushd is included in the "Mailsend.bat" because I need it to switch to this directory to execute the next "call" command after sending the email .

For the "FOR" loop, I divided all the "call" STATEMENTS into group (i.e A, B, C, D). and called "MailSend.bat" within the loop.

Code: [Select]:A
for /L %%a in (1,1,3) do (
call cmdline -configfile "%USERPROFILE%\XX\SchedConfig.txt"
popd
call ".\MailSend.bat"
echo A 15 minutes run for 15 users and 1 stage completed.
if %%a equ 3 goto B
)
popd is included because I need to to switch to  mailsend's directory before calling  "MailSend.bat"

Thanks again devcom
Would you mind reviewing other batch scripts for me and make suggestions where I can improve and make them more robust? Glad i could help
Quote
Would you mind reviewing other batch scripts for me and make suggestions where I can improve and make them more robust?

ok just PM me


Discussion

No Comment Found