I have a script that looks for unhealthy jobs per instance. I have 3 instances where one instance contains 18 jobs and the other 2 instances have less.

If a job from a certain instance is down, it would send an email alert.

So to search for that unhealthy job, the script I used is

instance1=(streamtool lsjobs -d domainname -i Instance1| grep -v yes | awk 'NR==3')
if [ ! -z "$instance1" ]; then
echo -e "List of unhealthy job/s for Instance1: \n $instance1" | mailx -s "$subject" -r "$mail_from" email@app
echo `date` "All jobs are healthy for Instance1"

So this gets verbose for the "Healthy" status column. It returns jobs that have "no" status and then an "if" command to indicate that if row 3 is empty, then all other rows are empty as well. But if row3 is not empty, then send an email with the list of unhealthy job/s. How do I include the job name on the subject individually if there are multiple unhealthy jobs?

Sample result: 
 Instance: Instance1
      Id State   Healthy User         Date                     Name                                                    Group
           3 Running no      user 2022-06-16T19:50:38+0000 job3  default


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.