Scheduled Task error code:The task completed with an exit code of

Discussion in 'Windows Server' started by Teo Chee Yang, Feb 26, 2007.

  1. I have a scheduled job running mailsed.exe for mail notification every 1
    hour. However, sometimes there are some error message in the schedlgu.txt log
    file as follow:

    "The task completed with an exit code of [ff]"

    Mai i know what does exit code ff means? Where can i find the exit code of
    scheduled tasks?
     
    Teo Chee Yang, Feb 26, 2007
    #1
    1. Advertisements

  2. The exit code is determined by the application you run,
    not by the Task Scheduler. What exactly is it?
     
    Pegasus \(MVP\), Feb 26, 2007
    #2
    1. Advertisements

  3. i'm running this mailsend.cmd file in this job:

    @ECHO OFF
    FOR /F "TOKENS=2 DELIMS= " %%1 IN ('date /T') DO SET currentDATE=%%1
    FOR /F "TOKENS=5 DELIMS= " %%2 IN ('type C:\Script\schedlgu\schedlgu.txt')
    DO SET fileDATE=%%2
    if exist filedate.txt del /q filedate.txt
    echo %fileDATE% >filedate.txt
    if exist concatdate.txt del /q concatdate.txt
    for /f "tokens=1 delims=/" %%A in ('type filedate.txt') do set mm=%%A
    echo %mm% >mm.txt
    if %mm% LSS 10 copy /b zero.txt+mm.txt concatdate-mm.txt
    trim /f:concatdate-mm.txt /r
    if %mm% GEQ 10 echo %mm% >concatdate-mm.txt
    trim /f:concatdate-mm.txt /r
    for /f "tokens=2 delims=/" %%B in ('type filedate.txt') do set dd=%%B
    echo %dd% >dd.txt
    if %dd% LSS 10 copy /b zero.txt+dd.txt concatdate-dd.txt
    trim /f:concatdate-dd.txt /r
    if %dd% GEQ 10 echo %dd% >concatdate-dd.txt
    trim /f:concatdate-dd.txt /r
    for /f "tokens=3 delims=/" %%C in ('type filedate.txt') do set year=%%C
    echo %year% >concatdate-yyyy.txt
    trim /f:concatdate-yyyy.txt /r
    copy /b
    concatdate-mm.txt+separator.txt+concatdate-dd.txt+separator.txt+concatdate-yyyy.txt concatdate.txt
    del /q dd.txt
    del /q mm.txt
    del /q concatdate-mm.txt
    del /q concatdate-dd.txt
    del /q concatdate-yyyy.txt
    del /q filedate.txt
    if not exist concatdate.txt goto :ENDNOW
    set /p concatDATE=<concatdate.txt
    if "%concatDATE%" == "%currentDATE%" goto :MATCHED
    goto :ENDNOW

    :MATCHED
    MAILSEND.exe -d xx.com -smtp xxxxx -t -f -sub "Failed
    Scheduled Job" < schedlgu.txt
    exit

    :ENDNOW
    exit

    it makes use of 2 exe file: mailsend.exe and trim.exe. Does the exit code ff
    indicates anything?

     
    Teo Chee Yang, Feb 26, 2007
    #3
  4. concatdate-mm.txt+separator.txt+concatdate-dd.txt+separator.txt+concatdate-y
    yyy.txt concatdate.txt
    There are several problems with your batch file:
    - You use overly complicated coding. Keep it simple - it
    will be much easier to debug!
    - You consistently fail to specify a drive and a path for your
    auxiliary files. This is bad. Instead of writing
    echo %fileDATE% >filedate.txt, you MUST write your code like so:
    echo %fileDATE% >c:\filedate.txt (for example)
    - You use two non-standard tools, trim.exe and mailsend.exe, but
    you don't say where these tools reside. You MUST state this
    in your batch file, e.g. like so:
    c:\tools\trim.exe /f: c:\concatdate-mm.txt /r
    - For the benefit of the administrators who come after you, you should
    include a descriptive header in your batch file like so:
    @echo off
    goto Start
    =========================================
    This batch file will do this:
    - ... (put your words here)
    - ...
    - ...
    Prerequisites: c:\tools\trim.exe
    c:\tools\mailsend.exe

    26 February 2007 Teo Chee Yang
    =========================================
    :Start
    set CurrentDate=%Date:~4%
    etc.

    I did not attempt to follow the logic of the batch file. If you still
    have a problem, post your modified version and explain the
    actual purpose of the batch file.


    @ECHO OFF
    FOR /F "TOKENS=2 DELIMS= " %%1 IN ('date /T') DO SET currentDATE=%%1
    *** Replace with: set CurrentDate=%Date:~4%

    FOR /F "TOKENS=5 DELIMS= " %%2 IN ('type C:\Script\schedlgu\schedlgu.txt')
    DO SET fileDATE=%%2
    *** Replace with:
    FOR /F "TOKENS=5 DELIMS= " %%a IN ('type C:\Script\schedlgu\schedlgu.txt')
    DO SET fileDATE=%%a

    if exist filedate.txt del /q filedate.txt
    *** Omit this line. It is not required.

    echo %fileDATE% >filedate.txt
    *** You must specify the exact file location, e.g.
    echo %FileDate% > c:\FileDate.txt

    if exist concatdate.txt del /q concatdate.txt
    *** You must specify the exact file location.

    for /f "tokens=1 delims=/" %%A in ('type filedate.txt') do set mm=%%A
    *** Much simpler to write set mm=%date:~4,2%

    echo %mm% >mm.txt
    *** You must specify the exact file location.

    if %mm% LSS 10 copy /b zero.txt+mm.txt concatdate-mm.txt
    *** You must specify the exact file locations.

    trim /f:concatdate-mm.txt /r
    *** You must specify the exact file locations for trim.exe and
    concatdate-mm.txt

    if %mm% GEQ 10 echo %mm% >concatdate-mm.txt
    *** You must specify the exact file location.

    trim /f:concatdate-mm.txt /r
    *** You must specify the exact file locations for trim.exe and
    concatdate-mm.txt

    for /f "tokens=2 delims=/" %%B in ('type filedate.txt') do set dd=%%B

    *** Much simpler to write set dd=%date:~7,2%

    echo %dd% >dd.txt

    *** You must specify the exact file location.

    if %dd% LSS 10 copy /b zero.txt+dd.txt concatdate-dd.txt

    *** You must specify the exact file location.

    trim /f:concatdate-dd.txt /r

    *** You must specify the exact file locations for trim.exe and
    concatdate-mm.txt

    if %dd% GEQ 10 echo %dd% >concatdate-dd.txt

    *** You must specify the exact file location.

    trim /f:concatdate-dd.txt /r

    *** You must specify the exact file locations for trim.exe and
    concatdate-mm.txt

    for /f "tokens=3 delims=/" %%C in ('type filedate.txt') do set year=%%C

    *** Much simpler to write set year=%date:~10,4%

    echo %year% >concatdate-yyyy.txt

    *** You must specify the exact file location.

    trim /f:concatdate-yyyy.txt /r
    *** You must specify the exact file locations for trim.exe and
    concatdate-year.txt

    copy /b
    concatdate-mm.txt+separator.txt+concatdate-dd.txt+separator.txt+concatdate-y
    yyy.txt concatdate.txt
    *** You must specify the exact file locations

    del /q dd.txt
    del /q mm.txt
    del /q concatdate-mm.txt
    del /q concatdate-dd.txt
    del /q concatdate-yyyy.txt
    del /q filedate.txt
    *** You must specify the exact file locations for the above files.

    if not exist concatdate.txt goto :ENDNOW
    *** Much simpler to write
    if not exist concatdate.txt goto :eof
    *** Note that :eof is an inbuilt label.

    set /p concatDATE=<concatdate.txt
    if "%concatDATE%" == "%currentDATE%" goto :MATCHED
    goto :ENDNOW

    *** Much simpler to write
    if not "%concatDATE%" == "%currentDATE%" goto :eof

    :MATCHED
    MAILSEND.exe -d xx.com -smtp xxxxx -t -f -sub "Failed
    Scheduled Job" < schedlgu.txt
    *** You must specify the exact file locations for the above files.

    *** Delete the remaining lines - you don't need any of them.
    exit
    :ENDNOW
    exit
     
    Pegasus \(MVP\), Feb 26, 2007
    #4
  5. I'm not a programmer, so i guess you will know it from the scripts that i've
    written below :)

    all the files generated/required should reside in C:\Script\schedlgu folder.
    that's why i didnt put the path in my script.

    do you think the error code ff are generated by the non standard trim.exe
    and mailsend.exe? or it it because of the other part of the script?

    appreciate your feedback. thanks.

     
    Teo Chee Yang, Feb 26, 2007
    #5
  6. You may not be a programmer but you have certainly
    picked up a few advanced skills in batch file programming!

    It's OK for you to place your files into the nominated
    folder but then you MUST start your batch file with
    the following lines:

    @echo off
    goto Start
    =========================================
    This batch file will do this:
    - ... (put your words here)
    - ...
    - ...
    Prerequisites: C:\Script\schedlgu\trim.exe
    C:\Script\schedlgu\mailsend.exe

    26 February 2007 Teo Chee Yang
    =========================================
    :Start
    cd /d C:\Script\schedlgu
    set CurrentDate=%Date:~4%

    The two utilities trim.exe and mailsend.exe must also reside
    in the same folder.


     
    Pegasus \(MVP\), Feb 26, 2007
    #6
  7. Few questions:

    1. For e.g. you wrote this:

    set CurrentDate=%Date:~4%

    may i know what does this %Date:~4% means? Any web site for reference?

    2. Do you think the error message ff comes from trim.exe and mailsend.exe?
    Or do they come from other part of the script? I ran this script every hour
    for 12 hours and normally i get 2 - 3 such errors a day.

    Appreciate your feedback. Thanks.

     
    Teo Chee Yang, Feb 26, 2007
    #7
  8. See below.

    The code means: Take the variable %date%, then return all
    characters from 4 onwards. Counting starts at 0. Thus the lines
    set name=GeorgeWBush
    echo %name:~7%
    will return "Bush". Run for /? from a Command Prompt to see full details.
    I don't have the faintest idea but if you generate some logs then
    you will soon find out: just examine c:\log.txt after the error
    has occurred - see below.
    @echo off
    goto Start
    =========================================
    This batch file will do this:
    - ... (put your words here)
    - ...
    - ...
    Prerequisites: c:\tools\trim.exe
    c:\tools\mailsend.exe

    26 February 2007 Teo Chee Yang
    =========================================
    :Start
    echo *********************** >> c:\log.txt
    echo %date% %time% >> c:\log.txt
    set CurrentDate=%Date:~4%
    etc.

    trim /f:concatdate-mm.txt /r 1>> c:\log.txt 2>>&1
    echo ErrorLevel of trim.exe=%ErrorLevel% 1>> c:\log.txt 2>>&1
    ... .. ..
    copy .. .. .. 1>> c:\log.txt 2>>&1
    ... .. ..
    mailsend /.. /.. 1>> c:\log.txt 2>>&1

    echo ErrorLevel of MailSend.exe=%ErrorLevel% 1>> c:\log.txt 2>>&1
     
    Pegasus \(MVP\), Feb 26, 2007
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.