Binary Operator expected while executing the below shell script.

Hi Experts,

Iam bit poor in shell scripting,
Here my requirement is for generating an alert where the oracle database db_recovery_file_dest_size usage. If it reaches beyond 80% should recieve an alert through an email.

Want to schedule this alert in cron.

#!/bin/bash
. /home/oracle/prod.env
echo " "
echo =======================================================================
echo archive_usage.sh:  $ORACLE_SID
echo To know the Archive/Db_recovery_area usage
date +"%A, %B %e, %r"
echo -----------------------------------------------------------------------
status=$(sqlplus -S system/PWD@$ORACLE_SID << ENDINP
set feedback off
set hea off
set verify off
SELECT METRIC_VALUE FROM SYS.DBA_OUTSTANDING_ALERTS where reason like '%db_recovery_file_dest_size%'
/
exit
ENDINP)
status=`echo $status`
echo "Archive Area usage is:" $status
if [ $status >= 80 ]; then
   mailx -s "PROD - Archive Area Usage is growing" "mjcprasad2000@gmail.com"
      Production PROD ARCHIVE Area is above 85%!!
   exit 1
else
mailx -s "PROD - Not in Thresholds" "mjcprasad2000@gmail.com"
   exit 0
fi

Please help me in sorting out this issue. :slight_smile:

Thanks & Regards,
-----------------
Jagadish.
Oracle Apps DBA.

Will this query

SELECT METRIC_VALUE FROM SYS.DBA_OUTSTANDING_ALERTS where reason like '%db_recovery_file_dest_size%'

returns only one row?

rewrite status=`echo $status` to status=$(echo "$status")

I don't have a database to test with, but at least one problem in your script is that in the command:

if [ $status >= 80 ]; then

the >= performs a string comparison (where 9 > 80 and 100 < 80 and 1 < 80). To perform a numeric comparison, try:

if [ $status -ge 80 ]; then

Yes, it returns 1 value.

Still it failed with same error.

Regards,
Jagadish.

status=`echo $status`

Isn't that redundant?

What was the error??

Before you said you had an issue (and didn't say what it was other than that you were trying to run your script in cron); now you're saying you're getting an error. Exactly what error(s) are you seeing? :mad:

That's a quick hack to trim leading and trailing white spaces from the variable.

@Jagadish m

Please post the output of this line:

echo "Archive Area usage is:" "$status"

Please note that the $status is in double quotes.

Did it have leading or trailing white spaces? I didn't see the logic of why it would.

Here is the error.

[oracle@is01xa1:/u01]$sh archive_usage.sh

=======================================================================
archive_usage.sh: prod
To know the Archive/Db_recovery_area usage
Friday, April 19, 01:26:30 PM
-----------------------------------------------------------------------
Archive Area usage is: Elapsed: 00:00:00.29
archive_usage.sh: line 23: [: 00:00:00.29: binary operator expected

I have already mentioned in the subject stating :mad:

---------- Post updated at 03:41 PM ---------- Previous update was at 03:29 PM ----------

Still getting as below:

not receiving the value of the variable status.

Archive Area usage is: Elapsed: 00:00:00.29

-Jagadish.