Solved

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

Posted on 2010-09-02
4
976 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
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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

809 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