1

I've some weird situation. My autosys job status shows that it ran successfully but when I checked the logs it showed it was failed.

Is that possible ? Has anyone encountered this kind of issue ?

Tim
  • 69
  • 7
  • can u share the error msg, exit code, background of the Autosys job, like what task does it trigger ? – Piyush Jun 21 '21 at 14:35
  • @Piyush, In autosys its showing exit code as "0", error message is simply a java application failed error due to some rest api issue. – Tim Jun 21 '21 at 14:37
  • what script does it trigger ? shell or java directly ? – Piyush Jun 21 '21 at 14:38
  • It a Java code.. – Tim Jun 21 '21 at 14:39
  • 1
    autosys marks the job status by exit code. your script should explicitly mention user defined exit code for autosys to mark them as failed. – Piyush Jun 21 '21 at 14:40
  • try to capture such a runtime, and pass "System.exit(101)" and your Autosys job should fail with 101 exit code – Piyush Jun 21 '21 at 14:42

1 Answers1

0

Use the -b option in the SQLCMD. This post gives a good explanation, and the solution worked for me... https://dba.stackexchange.com/questions/77298/how-to-make-sqlcmd-return-an-errorlevel-other-than-0-when-the-sql-script-fails

Taken from the above link...

You should use the option -b in sqlcmd.

-b Specifies that sqlcmd exits and returns a DOS ERRORLEVEL value when an error occurs. The value that is returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity level greater than 10; otherwise, the value returned is 0.

http://msdn.microsoft.com/en-us/library/ms162773.aspx

phredd
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '22 at 04:31