mardi 4 février 2020

Read output of an oracle query with a bash script

I am trying to setup a bash script within which a connection to an Oracle instance to check the various dba jobs scheduled and if a specific job is not running i need to display an error message.

Here is the script i have written and it works partially, the script works only until it reaches the IF statement

enter code here#!/usr/bin/env bash enter code here#write output of the sql query to an output file enter code hereoutput_file="/tmp/datatool_output.csv" enter code here> $output_file

enter code hereecho " enter code hereSET FEED OFF enter code hereSET PAGESIZE 0 enter code hereSET COLSEP , enter code hereSET linesize 100 enter code hereSET TRIMSPOOL ON enter code hereSET TRIMOUT ON

enter code hereSELECT JOB_NAME, STATE FROM DBA_SCHEDULER_JOBS where job_name ='run_LoadDatatoolStore';

enter code hereexit" | sqlplus -s sqlplus -s "username/password@dbip:dbport/SID" >> $output_file

 `enter code here`a_var=($(awk -F',' '{print $2}' $output_file | sed 's/\s//g' | xargs))

enter code herefor item in ${a_var[@]} enter code heredo enter code hereval=$(echo $item | awk -F',' '{print $1}')

enter code hereif [[ $val -eq "SCHEDULED" ]] || [[ $val -eq "RUNNING" ]] ; then enter code here echo "OK: The job LoadDatatool is either Scheduled or in the Running state" enter code here exit 0 # this is used for interpretation by nagios to display no alert alert enter code hereelse [[ $val -eq "BLOCKED" ]] enter code here echo "CRITICAL: The Db scheduler job LoadDatatool is in a Blocked state" enter code here exit 2 enter code herefi

I get test.sh: line 24: syntax error: unexpected end of file when i run the script Any help figuring this out is appreciated.

Thanks, Karthik

Aucun commentaire:

Enregistrer un commentaire