An AutoSys job executing a sendevent command (e.g., JOB_ON_HOLD) completes with SUCCESS (exit code 0) even if the target job fails to change its state. Users require the job to FAIL if the target state is not achieved.
The sendevent command is asynchronous by design. It returns a return code of 0 once the event is successfully queued in the AutoSys database. It does not wait for the Event Processor to pick up the event, nor does it verify if the event was successfully applied to the target job.
To force a job to fail based on the target job's state, you must implement a validation step using autorep. This can be done via a wrapper script or an inline command block.
sleep to allow the Event Processor time to process the database queue.autorep to check the status and explicitly exit 1 if the validation fails.#!/bin/bash
TARGET_JOB="MY_TARGET_JOB"
# 1. Fire the event
sendevent -E JOB_ON_HOLD -J $TARGET_JOB
# 2. Pause to allow the Event Processor to catch up
sleep 5
# 3. Capture the current status using autorep
# The 6th column in 'autorep -q' typically contains the status code (e.g., OH for ON_HOLD)
STATUS=$(autorep -J $TARGET_JOB -q | grep $TARGET_JOB | awk '{print $6}')
# 4. Evaluate and exit accordingly
if [ "$STATUS" = "OH" ]; then
echo "Success: $TARGET_JOB is now ON_HOLD."
exit 0
else
echo "Error: $TARGET_JOB is in status $STATUS instead of ON_HOLD."
exit 1
fi