|
Answer» Hi all, I am writing a batch file to check if data was entered into a database.
The batch file calls text files that run database queries and return the results in individual files. The batch file then checks to see if these newly created files have data. If they have 0 bytes (no data) an email is sent out warning that data was not recorded. If they have more than 0 bytes (data returned from the query) then the email section is skipped and another test on another query is begun. This happens until all checks are completed.
The problem I am having is that I am getting inconsistant returns, meaning that the batch file is sending emails out when it shouldn't. Is this a problem with the way I am coding this batch file? I could use any help offered as I am pretty new at this sort of thing.
REM **** Start of opstats daily data check **** REM **** Running SQLs to extract data if exists **** d: cd \opstats\verifydata mysql < d:\opstats\verifydata\climate.txt mysql < d:\opstats\verifydata\as400utilization.txt mysql < d:\opstats\verifydata\rs6000utilization.txt mysql < d:\opstats\verifydata\midnightprocess.txt mysql < d:\opstats\verifydata\3rdshiftbills.txt mysql < d:\opstats\verifydata\rs6000fullbu.txt mysql < d:\opstats\verifydata\rs6000incbu.txt mysql < d:\opstats\verifydata\rs6000jnlbu.txt
REM **** Pause to let SYSTEM catch up with happenings **** TIMEOUT 50 cls REM **** Something to check ****
cd \opstats dir *.* REM ****Begin process of checking for files**** REM ****Emails will be sent out if no data exists as a result of a query **** :check1 TIMEOUT 5 cls cd \opstats dir climateReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check2
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing Climate Data" -f Statistics_Database
:check2 TIMEOUT 5 cls cd \opstats dir as400UtilizationReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check3
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing AS400 Utilization Data" -f Statistics_Database
:check3 TIMEOUT 5 cls cd \opstats dir rs6kUtilizationReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check4
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing RS6000 Utilization Data" -f Statistics_Database
:check4 TIMEOUT 5 cls cd \opstats dir midnightProcessReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check5
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing Midnight Process Data" -f Statistics_Database
:check5 TIMEOUT 5 cls cd \opstats dir 3rdShiftBillReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check6
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing 3rd Shift Bill Data" -f Statistics_Database
:check6 TIMEOUT 5 cls cd \opstats dir rs6kFullBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check7
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing RS6000 Full Backup Data" -f Statistics_Database
:check7 TIMEOUT 5 cls cd \opstats dir rs6kIncBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto check8
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing RS6000 Incremental Backup Data" -f Statistics_Database
:check8 TIMEOUT 5 cls cd \opstats dir rs6kJnlBuReport.txt | c:\winnt\system32\find "0 bytes" > NUL if %ERRORLEVEL% NEQ 0 goto end
cd \opstats\verifydata blat d:\opstats\verifydata\messagebody.txt -to [emailprotected] -subject
"Stats DB Missing RS6000 Journal Backup Data" -f Statistics_Database
:end TIMEOUT 5 cls REM **** Data checking has completed **** REM **** Clean up to begin next ****
:cleanup del d:\opstats\climateReport.txt del d:\opstats\as400UtilizationReport.txt del d:\opstats\rs6kUtilizationReport.txt del d:\opstats\midnightProcessReport.txt del d:\opstats\3rdShiftBillReport.txt del d:\opstats\rs6kFullBuReport.txt del d:\opstats\rs6kIncBuReport.txt del d:\opstats\rs6kJnlBuReport.txt TIMEOUT 5 cls REM ****ALL Processing and Cleanup is complete**** TIMEOUT 5There does not appear to be any GLARING logic errors in your code. Double check that the input files to mysql are doing what you think they are doing. For debugging purposes, turn off the deletes at the bottom of the file and manually check whether an email should have been sent or not.
Good luck. I've done all that, I have run it without the deletes to verify data or LACK of data to make sure the files were CORRECT. It seems as though it is not reading the filesizes correctly all the time. For EXAMPLE, this morning when I came in I ran the batch file after reading the reply and it again did not run correctly. When it got to the rs6kUtilizationReport.txt file which is 281 bytes it sent out an email, this should have not happened. I deleted the files and with the same data being generated, the email did not get sent when I reran the batch file a second time.
What is the whole find "0 bytes" > NUL statement, I had found it online and seemed to be what I was looking for. What does it EXACTLY mean? Is there a way to rephrase this statement to work for me? Is the statement just checking the last place of the file size area? Could it be rounding? My deadline for this "simple" project is fast approaching...There are a few ways to do this, none of them pretty.
Code: [Select] for /f "tokens=1-4" %%a in ('dir filename.ext ^| find "filename"') do (if %%d EQU 0 goto wherever)
Change filename, ext and wherever to something appropriate and replace your errorlevel checks with this line.
Hope this helps.
|