

InterviewSolution
Saved Bookmarks
1. |
Solve : Help with batch file and IF command? |
Answer» <html><body><p>I am trying to write a batch <a href="https://interviewquestions.tuteehub.com/tag/file-11330" style="font-weight:bold;" target="_blank" title="Click to know more about FILE">FILE</a> on a Windows 2003 Server that will do two things to hopefully make my life a little easier. The first thing I <a href="https://interviewquestions.tuteehub.com/tag/want-1448756" style="font-weight:bold;" target="_blank" title="Click to know more about WANT">WANT</a> it to do is search through a log file and see if a word or phrase exists. Second if it finds a match in the log file I want it to email the log file to me.<br/><br/>I some what have a working file for each piece but am unable to get them to work together. For the search piece I am able to run this:<br/><br/>find /i /c "test" "D:\Housekeeping Scripts\Logs\Test.txt"<br/><br/>I was redirecting this into another txt file where it would store:<br/><br/>---------- D:\HOUSEKEEPING SCRIPTS\LOGS\TEST.TXT: 0<br/><br/>That works, and I can email the log file to myself everytime the script runs whether it has found a match or not but what I <a href="https://interviewquestions.tuteehub.com/tag/really-1178981" style="font-weight:bold;" target="_blank" title="Click to know more about REALLY">REALLY</a> want if for it to only email it to me if it finds a match. I can't seem to tell if find is supposed to return a result <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a> or not.<br/><br/>What I would like to see is something like this:<br/><br/>if (find more than one match)<br/>{ <br/> send me an email (have a tool for this already)<br/>{<br/><br/>Was trying to just use the DOS IF command but I couldn't get it to work. It doesn't have to be the DOS IF command though but it does have to be something I can incorporate into other scripts.<br/><br/>Any help would be greatly appreciated.<br/><br/>Adam</p></body></html> | |