I want to write a batch script statement where:
FINDSTR has to check for a string AND IF found then just print out FAILED and end the program
IF NOT FOUND then go check/look for another string AND IF FOUND then print out SUCCEEDED and close the program, IF NOT FOUND then print out the error message again.
Any ideas?
Here is what I did:
ECHO Checking the log file for errors...
FINDSTR /C:"Open failed" some_Log.txt && (ECHO Deployment FAILED.
cscript //nologo success_mail.vbs
pause) || FINDSTR "RC (return code) = 0" && (ECHO Deployment was successful.
cscript //nologo fail_mail.vbs
pause)
I don’t know why it is not working. Any help would be appreciated.
Here is what i my latest one looks like:
ECHO Checking the log file for errors...
FINDSTR /C:"Open failed" some_Log.txt some_Log.txt && (
ECHO Deployment FAILED.
cscript //nologo fail_mail.vbs
GOTO offshore ) || (
FINDSTR /C:"RC (return code) = 0" some_Log.txt && (
ECHO Deployment was successful.
cscript //nologo success_mail.vbs
GOTO offshore)
)
And, it is not working. Do you see any errors? Thanks in advance.
I see a couple of potential problems.
Your
%workDir%or%filenm%could contain spaces or special characters. To be safe you should enclose them in quotes if you haven’t already done so in the values.You must be careful when using both
&&and||operators. If the command(s) after the&&fail, then it can cause the script to fall into the||section, even though the original command before the&&succeeded. I’m worried about your CSCRIPT command to send mail. Even if it succeeds today, perhaps it could fail in the future and your logic could be impacted.I’m guessing that the 2nd search string is supposed to be a phrase and not 5 different searches. Remember that search strings are delimited by space unless the /C option is used.
Your 2nd FINDSTR is hanging because you have neglected to provide a file as input, so it is waiting for data on stdin.
I would structure your code like so