SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
How can I force a job status to fail?
Goto page 1, 2  Next
 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
How can I force a job status to fail?
Author Message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post How can I force a job status to fail? Reply with quote
Hello,

I am using jscheduler 4.1 build 242, and I have a job that if successful, will write a semaphore file.
I set the successful exit code to “0”.
The job is a windows batch file, that contains some logic that if there are no files to process, I would like to return a status of “failed”.

I added a bogus copy command and even syntax errors to modify %errorlevel% to be different than “0”, and that works (echo The EL is now %errorlevel%>>c:\EL.txt). Unfortunately, 24x7 still reports the job as successful and thus places the semaphore file I would like to avoid.

How can I (from a batch file) force the job to have a status of “Failed”?

Thanks.
Wed Oct 03, 2007 8:12 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
The default exit code of a batch file is the exit code of the last executed command. If you put "echo" at the end, you are going to get exit code of echo, not what you want

To return something else, either use generic
Code:
EXIT %ERRORLEVEL%
or just hard code the required exit code

Code:
IF "%1" == "" GOTO PRINT_ERROR

IF EXIST *.txt GOTO PROCESS_THEM
ECHO Couldn't find *.txt files
EXIT 1

:PRINT_ERROR
ECHO You didn't specify the required command line parameter
EXIT 2

:PROCESS_THEM
Run something here

Wed Oct 03, 2007 8:58 pm View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
Thanks for the swift response :-)

I tried it today with the below code:
Code:

:NothingToPRocess
Echo !!!!!!! WonderBatch.bat did not find files to transffer on %date% at %time% >>C:\Interesting.log
REM The next line will generate an errorlevel different than "0" so we know it did not find any files and will NOT post a semaphore on 24x7.
Exit 2
Echo Sanity Check on %date% at %time% >>C:\Interesting.log
:Finish


The job still completes successfully and note that the Sanity Check echo does not show up in C:\Interesting.log so I am assured it is being Exited as requested with errorlevel=2.

BTW, I do not think it matters but I will mention it anyhow, this job is run on an agent not the 24x7 Master server itself.
The agent got installed with:

Code:

24x7srv.exe /install
24x7srv.exe /install /agent


(Trying the 2nd line by itself first did not give me any confirmation that it was done)

Thanks for your help.
Thu Oct 04, 2007 10:28 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
I have verified that if a batch file is run remotely and the job is set to fail on error and successful exit code 0 is entered in the job properties, the job fails all the way and the agent makes the master scheduler aware of the job failure. Please verify how the job is setup. Whether it actually has zero entered for the successful exit code and if it set to run attached/detached.
Thu Oct 04, 2007 3:06 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
By the way, the second line won't likely work.

24x7srv.exe /install
24x7srv.exe /install /agent


If the service has been already registered in normal mode and you need to convert it to agent mode, remove the service registration first and add it again with the /agent option.

24x7srv.exe /remove
24x7srv.exe /install /agent

Thu Oct 04, 2007 10:37 pm View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
I have confirmed the job properties show successful exit code of 0, and the process runs as "Detached" (Actually it is defaulted as detached and I can not change it I can only select Async).

I stopped the service and started the Agent.bat to avoid having to troubleshoot the service for now.
The job still does not fail.

I know you usually get people asking you the opposite "how to fix things that fail" and I want them to fail, what more can I try?

:-)

Thanks.
Fri Oct 05, 2007 3:08 pm View user's profile Send private message
jvaldes988



Joined: 01 Mar 2007
Posts: 35
Country: United States

Post Reply with quote
Please keep this thread alive since we have a similar issue with one of our jobs.

Thanks.
Fri Oct 05, 2007 3:22 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
Have you been able to figure out the cause of the issue? I mean why the exit code of the batch process is not returned/treated as an error?
Fri Oct 05, 2007 6:55 pm View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
:-(
Not yet.

Help please.

Thanks.
Mon Oct 08, 2007 4:56 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
Please let us know what you get when executing
runas.exe your_user_name your_password "the batch you want to run"

The output of this command should provide the clue to the job completion status
Tue Oct 09, 2007 8:56 am View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
Hello again,
When I run the 24x7 version of runas I get:

RunAs version 2.1
Copyright (c) 2003-2006 SoftTree Technologies, Inc.

Logging in as .\renameduser...
Setting user environment...
Logged in. Impersonating...
Starting process C:\batchname.bat...
Waiting for process to complete...
Process completed with exit code 2

So the batch is actually providing the correct exit code, for some reason 24x7 sees it as 0 instead of 2.

What else can I check?
Tue Oct 09, 2007 4:46 pm View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
Running the agent in GUI mode with trace on, I get from debug.log:


    2007-10-09 17:21:49,780 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - runJob(): start
    2007-10-09 17:21:49,780 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.security.SecurityService - authNativeUser: C:\Program Files\24x7_Scheduler\userchk.exe
    2007-10-09 17:21:49,843 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - execProcess(): command line [c:\batch\renamedbatch.bat] in work directory [c:\batch\]
    2007-10-09 17:21:49,874 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - waitForProcess(): start
    2007-10-09 17:21:49,874 [Thread-5] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run(): start
    2007-10-09 17:21:49,874 [Thread-5] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run(): end due to zero timeout
    2007-10-09 17:21:49,999 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - waitForProcess(): end
    2007-10-09 17:21:49,999 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner - isFailed(...) : exit code 0
    2007-10-09 17:21:49,999 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - killProcess start
    2007-10-09 17:21:49,999 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - runJob(): end
    2007-10-09 17:25:07,915 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - runJob(): start
    2007-10-09 17:25:07,915 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.security.SecurityService - authNativeUser: C:\Program Files\24x7_Scheduler\userchk.exe
    2007-10-09 17:25:07,930 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - execProcess(): command line [c:\batch\renamedbatch.bat] in work directory [c:\batch\]
    2007-10-09 17:25:07,930 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - waitForProcess(): start
    2007-10-09 17:25:07,930 [Thread-7] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run(): start
    2007-10-09 17:25:07,930 [Thread-7] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run(): sleeping. Max wait time is 180000 milliseconds
    2007-10-09 17:25:08,039 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - waitForProcess(): end
    2007-10-09 17:25:08,039 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner - isFailed(...) : exit code 0
    2007-10-09 17:25:08,039 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - killProcess start
    2007-10-09 17:25:08,039 [Job #514 - Test-job] DEBUG com.softtreetech.jscheduler.business.runner.ProgramJobRunner - runJob(): end
    2007-10-09 17:25:08,039 [Thread-7] INFO com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run():
    java.lang.InterruptedException: sleep interrupted
    at java.lang.Thread.sleep(Native Method)
    at com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier.run(Unknown Source)
    2007-10-09 17:25:08,086 [Thread-7] DEBUG com.softtreetech.jscheduler.business.runner.AbstractJobRunner$TimeoutVerifier - run(): ended


As you can see I tried with and without timeout interval.

I can not explain why runas.exe works and the agent will not see the correct exit code..... Help!

Thanks.
Tue Oct 09, 2007 5:40 pm View user's profile Send private message
24x7addict



Joined: 03 Oct 2007
Posts: 7
Country: United States

Post Reply with quote
OK,
Refusing to give up on this, I tried setting up the agent as a master and run the job locally.

I wrote a batch file called Failed.bat

Code:

REM This batch should fail with the below exit code.
Exit 3


I noticed that the job still succeeded, so I removed the "Apply Credentials" and it finally failed with an exit code of 3 as desired.

So the problem is caused by applying credentials: Either as machinename\username or .\username

The user starting the job is the same user I am using to run the GUI Master.bat.

What are your recommendations from here?
Tue Oct 09, 2007 7:17 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7841

Post Reply with quote
I am unable to reproduce the same results. What Windows version are you running?

Please try the following
1. In the batch file replace "exit 2", "exit 3" and similar commands with "echo ERROR"
2. change job type in 24x7 from "Program" to "Script" and choose JavaScript for the script type
3. In the job script enter

Code:
var runInfo = Process.runAndWait("C:\\path\\to\\file\\mybatch.bat", 0);
if(runInfo.getOutput().indexOf("ERROR") >= 0)
     makeJobFail;  // this invalid command will make the job to fail

Wed Oct 10, 2007 3:26 am View user's profile Send private message
kyofm



Joined: 30 Sep 2014
Posts: 21

Post Reply with quote
I am encountering an interesting problem in 24x7 trying to achieve the same goal as the original poster and I will try to be as clear as possible.

Here is my test code:
IF NOT EXIST C:\Users\...\Desktop\test.txt GOTO PRINT_ERROR

:PRINT_ERROR
EXIT 1

If I create a job that runs a batch file with the code above (and the file does not exist on my Desktop) and set the success exit code to 0 in 24x7 I get the functionality I want i.e. not finishing the job and not creating a semaphore file. However, what I really want is to be able to embed the code above as a script in 24x7. When I do this, however, the job finishes and creates a semaphore file. When selecting to a run the code as a script in the job builder there is no place to set the success exit code to 0 since it says error code checking is automatic.

Now for the weird part, if I go through the process of running the batch file as a program and set the exit code to 0, run the job and then change the job properties to run a script and embed the batch in 24x7 the job fails like it is supposed to. How can I trust this?
Wed Oct 15, 2014 7:40 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.