1.

Solve : Notify page when a batch file crashes.?

Answer»

Hello all,

I have more than 15 batch files that they perform a lot of actions (Robocopy, sent emails, etc).
I want to ask if it's possible to have a page (ASP.NET or PHP) where when a batch file crashes or hangs, the page should write smth.
For example will write "Batch file Robocopy" and when it crashes should be "Batch file Robocopy Crashed"
What do you thing, is possible smth like that?I made a monitor in the past that was written in C++ that was a scheduled task that checked on automated processes/ batches as to if they ran or not successfully. At the end of my batch instructions I added

echo. %date%>Routine1_log.txt

In my C++ program it verified the date in this file Routine1_log.txt with the current date. If they matched all was well, however if this file had yesterdays date in it, then I know that the batch did not complete. In my C++ program if a failed automation process was detected I would receive an e-mail with the process that did not complete.

You will need to use a similar routine to test and verify that it was completed. My suggestion is to make a log file entry similar to what i did and have a process that is scheduled monitor for failure on timed intervals. Such as when the process should have completed and hasnt looking for a date match etc.Thank you for your reply,

Can you plz share your c++ program, the things i want are similar to your program.Will SEE if I can dig it up. Haven't used it in over 5 years. Couldn't find my program, but rounded up a better way to do it that is easier just using file compare. In the C++ program I read in contents from 2 files and performed a string compare, but now that I realized that this can be done way easier using FC, I wish i did that back then vs reinventing the wheel...LOL

Code: [Select]@echo off
echo %date%>todays_date.txt

fc c:\test\todays_date.txt c:\test\Last_Run.txt > nul
if errorlevel 1 goto mismatch

:next
exit

:mismatch
echo Mismatch, running notification
START emailme.bat
This batch will exit if they match and start emailme.bat if the dates mismatch between SAY todays date and what should also be todays date in the batch log file created by adding echo %date%>Last_Run.txt to existing batch.

emailme.bat started if there is a mismatch will use Windows Power Shell to email you by creating a batch file with info such as the following example from http://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/ :
Quote

$EmailFrom = “[emailprotected]
$EmailTo = “[emailprotected]
$Subject = “The subject of your email”
$Body = “What do you want your email to say”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

I used a different tool to e-mail myself via command line, but this should be all you need editing for PATHS and piecing this together to make it happen.

Thank you very very much for your reply and for the time you spent to write the code.
I will try it and i will inform you about the results.


Discussion

No Comment Found