Results 1 to 4 of 4

Thread: Batch Script Issue

  1. #1
    Join Date
    Aug 2013
    Posts
    2

    Batch Script Issue

    Hi, all,

    I am using a command line program called blat to send emails and I have confirmed this portion is working without an issue.

    I then wrote another batch script to find a task running in the task manager using the tasklist command. I can write this information out to a file without issue.

    My problem is that no matter what I do, the blat script (dos) will not send anything for me. I have even gone as far as writing the error level out to a file to see what the value is when the application being checked is running and not running.

    When the application to check is running, the error level being written out is zero. When the application to check is not running, the error level being written out is one.

    This is what I have... any ideas as to where I am going wrong?
    Also, as a side note, the text file is not even deleted, so looks like the script doesn't even get that far!

    Code:
    @ECHO OFF & SETLOCAL ENABLEDELAYEDEXPANSION
    
    ::Install blat in the registry each time this program runs otherwise it will not send out the notification email.
    \\vdifiles\blat$\blat.exe -install mailserver.mydomain.com alerts@mydomain.com
    
    ::Lets see if the executable is in the Task Manager, Processes tab.
    ::Write this check out to a file.
    TASKLIST /FI "STATUS EQ running" /FI "IMAGENAME EQ nsoftware.AS2Connector.exe" /FI "USERNAME EQ c$yp1504" /FO LIST >> RunningTasks.txt
    
    ::Let's check the RunningTasks.txt file to see if nsoftware.AS2Connector.exe is contained within.
    FINDSTR "nsoftware.AS2Connector.exe" < RunningTasks.txt
    IF %ERRORLEVEL% = 0 CALL blat-found
    IF %ERRORLEVEL% = 1 CALL blat-notfound
    
    ::Do some cleanup.
    DEL RunningTasks.txt /S /F
    ENDLOCAL
    When the process is found and then written out to the file, it shows like the screen shot attached. Please advise. Thanks.
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Batch Script Issue

    You'll likely need to write you own, use this script to get started. It's basically done for you. Just set the relevant variables and tweak as needed.

    You can try to write your own script or else you can use the script that is given below to see if it works for you or not:

    Code:
    @echo off
    setlocal enabledelayedexpansion
    cd /d "%~dp0"
    if not exist blat.exe (
    	echo Requires http://sourceforge.net/projects/blat/files/
    	goto :eof
    )
    set log=%0.log
    call :logit EZ Monitor v1.0a by Giovanni started on %date% at %time%
    set process=calc.exe
    set ext1=txt
    set ext2=bak
    set folder=.
    set recipient="user@domain.com"
    set server=127.0.0.1:25
    set sender="<user@domain.com>"
    set username="user"
    set password="password"
    
    :process
    tasklist|findstr /i /c:"!process!">nul 2>&1
    if errorlevel 0 if not errorlevel 1 (
    	call :logit * !process! running.
    )
    if errorlevel 1 if not errorlevel 2 (
    	call :logit * !process! not running.
    	start !process!
    )
    
    :extension1
    dir /a-d !folder!\*.!ext1!>nul 2>&1
    if errorlevel 0 if not errorlevel 1 (
    	call :logit * .!ext1! file found.
    	blat -to !recipient! -subject "ALERT: .!ext1! file found." -body ".!ext1! file found in !folder! on %date% at %time%" -server !server! -f !sender! -u !username! -pw !password! -log !log! -debug>nul 2>&1
    )
    if errorlevel 1 if not errorlevel 2 (
    	call :logit * .!ext1! file not found.
    )
    
    :extension2
    dir /a-d !folder!\*.!ext2!>nul 2>&1
    if errorlevel 0 if not errorlevel 1 (
    	call :logit * .!ext2! file found.
    )
    if errorlevel 1 if not errorlevel 2 (
    	call :logit * .!ext2! file not found.
    	blat -to !recipient! -subject "ALERT: .!ext2! file not found." -body ".!ext2! file not found in !folder! on %date% at %time%" -server !server! -f !sender! -u !username! -pw !password! -log !log! -debug>nul 2>&1
    )
    goto :eof
    
    :logit
    echo %*&title %*&echo %*>>!log!

  3. #3
    Join Date
    Aug 2013
    Posts
    2

    Re: Batch Script Issue

    I am trying to find the EZ Monitor and I am not able to find it. Do you have any ideas as to where I can download it?

  4. #4
    Join Date
    Dec 2007
    Posts
    1,736

    Re: Batch Script Issue

    Quote Originally Posted by spmaguire View Post
    I am trying to find the EZ Monitor and I am not able to find it. Do you have any ideas as to where I can download it?
    What is EZ Monitor and why do you need it?

Similar Threads

  1. Batch Script to Convert PNG to XPM
    By BRIGHID in forum Operating Systems
    Replies: 3
    Last Post: 22-08-2010, 03:25 AM
  2. Batch script to delete directory
    By Logan 2 in forum Software Development
    Replies: 4
    Last Post: 01-04-2010, 12:31 PM
  3. Need a batch script to map drive
    By Common in forum Networking & Security
    Replies: 3
    Last Post: 06-07-2009, 07:42 PM
  4. Several. Msc window from a batch / script call?
    By Stephanatic in forum Technology & Internet
    Replies: 2
    Last Post: 26-11-2008, 05:26 PM
  5. How can I play a Wav file from batch/cmd script?
    By NaFula in forum Windows Vista Performance
    Replies: 3
    Last Post: 13-09-2008, 09:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,482,012.58749 seconds with 18 queries