Announcement

Collapse
No announcement yet.

parse textfile+mail in batch

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • parse textfile+mail in batch

    HI,

    at the moment, I only have a command for searching a string into my a text file and print it :
    for /f "tokens=*" %%i in ('findstr /l "completed" text.txt') do echo %%i

    It works.

    Now, I would like to do the following:

    if the string which has been searched (see above) exists into the text file a mail with subject "OK" will be fired up with blat
    if not a mail with subject "Error" will be fired up

    I know how to use blat, I would just just need teh if commands...

    Thanks in advance.

  • #2
    Re: parse textfile+mail in batch

    maybe this way,

    Code:
    @echo off & setlocal
    
    Set "Completed="
    for /f "usebackq delims=" %%i in ("text.txt") do (
       >nul (echo\%%i | findstr /i "\<completed\>"
         ) &&(Set "Completed=True" & goto:exitFor
         ) ||(Set "Completed=False")
    )
    :exitFor
    
    If not defined Completed (
       call:fireblad "major ERROR notification"
       goto:end)
    If /i [%Completed%]==[TRUE] (
       call:fireblad "OK notification"
       goto:end)
    If /i [%Completed%]==[FALSE] (
       call:fireblad "ERROR notification"
       goto:end)
    
    endlocal
    :end
    
    
    goto:eofireblad -----
       :fireblad subroutine
       echo Blad sends "%~1"
       exit /b 0
    :eofireblad ------------
    Or,

    Code:
    @echo off
    
    >nul findstr.exe /i "\<completed\>" "text.txt" &&(
       call:fireblad "OK notification"  "[email protected]"
       goto:end)
    call:fireblad "ERROR notification"  "[email protected]"
    
    :end
    
    
    goto:eofireblad -----
       :fireblad subroutine
       echo Blad sends "%~1" to %~2
       exit /b 0
    :eofireblad ------------
    \Rems
    Last edited by Rems; 12th November 2009, 07:58.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: parse textfile+mail in batch

      with your help I finally could achieve my script.


      Thanks a lot man.

      Comment

      Working...
      X