Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
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.:

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now