Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 55
bash script question (chmod) 10 56
CentOS 7 Installation 7 59
expectj telnet failing 5 26
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

895 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

14 Experts available now in Live!

Get 1:1 Help Now