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

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

: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

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

24x7addict

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

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

jvaldes988

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

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

Thanks.

Fri Oct 05, 2007 3:22 pm

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

24x7addict

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

:-(
Not yet.

Help please.

Thanks.

Mon Oct 08, 2007 4:56 pm

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

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

24x7addict

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

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

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6642

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

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?