Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shell Script Help : [ Error -gt: unary operator expected ]

Posted on 2010-09-02
4
Medium Priority
?
1,036 Views
Last Modified: 2012-05-10
Gents,
I am trying to get a SHELL script working .

It is spitting error
[oracle@scripts]$ ./dg.sh
./dg.sh: line 39: [: -gt: unary operator expected
./dg.sh: line 43: [: -gt: unary operator expected



#!/bin/bash
#set Oracle environment for Sql*Plus
ORACLE_HOME=/u01/app/oracle/product/10.2.0 ; export ORACLE_HOME
ORACLE_SID=pegaprod ; export ORACLE_SID
PATH=$PATH:/u01/app/oracle/product/10.2.0/bin

#set working directory. script is located here..
cd /home/oracle/scripts

#Problem statement is constructed in message variable
MESSAGE=""

#hostname of the primary DB.. used in messages..
HOST_NAME=`hostname`

#who will receive problem messages.. DBAs e-mail addresses seperated with space
# DBA_GROUP='dba1@company.com dba2@company.com'

#SQL statements to extract Data Guard info from DB
LOCAL_ARC_SQL='select archived_seq# from V$ARCHIVE_DEST_STATUS where dest_id=1; \n exit \n'
STBY_ARC_SQL='select archived_seq# from V$ARCHIVE_DEST_STATUS where dest_id=2; \n exit \n'
STBY_APPLY_SQL='select applied_seq# from V$ARCHIVE_DEST_STATUS where dest_id=2; \n exit \n'

#Get Data guard information to Unix shell variables...
LOCAL_ARC=`echo $LOCAL_ARC_SQL | sqlplus -S / as sysdba | tail -2|head -1`
STBY_ARC=`echo $STBY_ARC_SQL | sqlplus -S / as sysdba | tail -2|head -1`
STBY_APPLY=`echo $STBY_APPLY_SQL | sqlplus -S / as sysdba | tail -2|head -1`

#Allow 20 archive logs for transport and Apply latencies...
let "STBY_ARC_MARK=${STBY_ARC}+20"
let "STBY_APPLY_MARK= ${STBY_APPLY}+20"

if [ $LOCAL_ARC -gt $STBY_ARC_MARK ] ; then
MESSAGE=${MESSAGE}"Error on $HOST_NAME Standby -log TRANSPORT- service! \n local_Arc_No=$LOCAL_ARC but stby_Arc_No=$STBY_ARC \n"
fi

if [ $STBY_ARC -gt $STBY_APPLY_MARK ] ; then
MESSAGE=${MESSAGE}"Error on $HOST_NAME Standby -log APPLY- service! \n stby_Arc_No=$STBY_ARC but stby_Apply_no=$STBY_APPLY \n"
fi

if [ -n "$MESSAGE" ] ; then
MESSAGE=${MESSAGE}"\This problem may cause the archive directories to get full!!! \n .\n "
echo $MESSAGE
fi
0
Comment
Question by:crazywolf2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33588806
Please echo out your variables just preceeding the first "if" to see waht they contain:

...
...
echo STBY_ARC $STBY_ARC
echo STBY_APPLY $STBY_APPLY
echo STBY_ARC_MARK $STBY_ARC_MARK
echo STBY_APPLY_MARK $STBY_APPLY_MARK

if  [ ...
...


wmp
0
 
LVL 19

Expert Comment

by:jools
ID: 33590547
Do you have values in each of your variables?
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 2000 total points
ID: 33591034
I re-wrote your script, take a look:


#!/bin/bash
#set Oracle environment for Sql*Plus
export ORACLE_HOME=/u01/app/oracle/product/10.2.0
export ORACLE_SID=pegaprod
export PATH=$PATH:$ORACLE_HOME/bin

#set working directory. script is located here..
cd /home/oracle/scripts

#Problem statement is constructed in message variable
MESSAGE=""

#hostname of the primary DB.. used in messages..
HOST_NAME=`hostname`

#who will receive problem messages.. DBAs e-mail addresses seperated with space
# DBA_GROUP='dba1@company.com dba2@company.com'

#Get Data guard information to Unix shell variables...

MESSAGE=`
sqlplus -s $LOGIN <<EOSQL
set pages 0 feed off
set serverout on size 1000000;
Var Rc Number;
Declare
  Local_Arc		Number:=0;
  Stby_Arc		Number:=0;
  Stby_Apply		Number:=0;
  Msg			Varchar2(4000):='';
Begin
  :Rc:=0;
  Select Archived_Seq# Into Local_Arc
    From V\\$Archive_Dest_Status Where Dest_Id=1;
  Select Archived_Seq#, Applied_Seq#
    Into Stby_Arc, Stby_Apply 
    From V\\$Archive_Dest_Status Where Dest_Id=2;
  If Local_Arc > Stby_Arc + 20 Then
    Msg:=Msg||'Local_Arc_No='||Local_Arc||' but Stby_Arc_No='||Stby_Arc||Chr(10);
    :Rc:=1;
  End If;
  If Stby_Arc > Stby_Apply + 20 Then  
    Msg:=Msg||'Stby_Arc_No='||Stby_Arc||' but Stby_Apply_No='||Stby_Apply||Chr(10);
    :Rc:=1;
  End If;
  If :Rc != 0 Then Dbms_Output.Put_Line(Msg); End If;
End;
/
exit :rc
EOSQL
if [ $? -ne 0 ]; then
  MESSAGE="Error on $HOST_NAME Standby -log APPLY- service!\n${MESSAGE}\nThis problem may cause the archive directories to get full!!!\n\n"
  echo -e $MESSAGE
fi

Open in new window

0
 

Author Closing Comment

by:crazywolf2010
ID: 33595225
Excellent work by MikeOM_DBA.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question