Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: awk question

RE: awk question

From: Srinivasan Vasan <Vasan.Srinivasan_at_churchill.com>
Date: Thu, 10 Jun 2004 09:52:26 +0100
Message-ID: <4661DD1EF5C4EF4B9D2BCE3A3E52EF3304C31E07@brcexm04.churchill.com>


Time to implement some standards in your shell scripts. Always enclose variable evaluations within double-quotes. For example, if [ "$variable" -gt "10" ] will not produce the same error as if [ $variable -gt "10" ] when variable happens to be unset. I personally prefer "${variable}" to make it even more explicit.

Cheers,

Vasan.

-----Original Message-----
From: David Green [mailto:thump_at_cosmiccooler.org] Sent: 09 June 2004 18:09
To: oracle-l_at_freelists.org
Subject: awk question

Thanks for the advice on the Darrell!
I am trying to implements and running into an issue. Can you or anyone else provide some additional guidance, it is much appreciated.

Here is what I have thus far:
#!/bin/ksh

SID=$1
cd /m1/homes/oracle
. ./$SID export WARNING_THRESHHOLD=55
export CRITICAL_THRESHHOLD=65

export TBS_WARNING=`orastat -ts | awk '{print $10}' | grep -vi generic | grep -vi pct | grep -vi === | grep -vi listed | grep -vi accurat` export TBS_CRITICAL=`orastat -ts | awk '{print $10}' | grep -vi generic | grep -vi pct | grep -vi === | grep -vi listed | grep -vi accurat`

export CHK_TBS_WARNING="$TBS_WARNING $WARNING_THRESHHOLD"
export CHK_TBS_CRITICAL="$TBS_CRITICAL $CRITICAL_THRESHHOLD"
export CHK_TBS_WARNING_EVAL=`echo $CHK_TBS_WARNING | awk '{if ($1 > $2)
print $1}'`
export CHK_TBS_CRITICAL_EVAL=`echo $CHK_TBS_CRITICAL | awk '{if ($1 > $2) print $1}'`

if [ $CHK_TBS_CRITICAL_EVAL -gt 65 ]; then

       ./orastat -ts|mailx -s "TBS CRITICAL for $SID" dgreen-email elif [ $CHK_TBS_WARNING_EVAL -gt 55 ]; then

       ./orastat -ts|mailx -s "TBS WARNING for $SID" dgreen-email fi

I receive the following, when trying to run: ./check_tbs.sh[18]: test: argument expected ./check_tbs.sh[20]: test: argument expected

I think it is because the CHK_TBS_WARNING_EVAL and CHK_TBS_CRITICAL_EVAL systax I'm using is not working. I think that is due to the tbs percents are being returned as a row of numbers and thus the comparision of $1 > $2 is no good:

+ SID=SDTEST01
+ cd /m1/homes/oracle
+ . ./SDTEST01
+ test

/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sony-bin:/usr/local/ etc:/usr/ucb:/usr/bin/X11:/usr/dt/bin:/usr/openwin/bin:/opt/SUNWspro/bin:/us r/ccs/bin:.
= X
+ ORACLE_SID=SDTEST01
+ ORACLE_BASE=/opt/app/oracle
+ ORACLE_HOME=/opt/app/oracle/product/9.2.0.4
+ ORACLE_PATH=/opt/app/oracle/product/9.2.0.4/bin
+ ORACLE_TERM=vt100
+ INIT=/opt/app/oracle/admin/SDTEST01/pfile/initSDTEST01.ora
+ ALERT=/opt/app/oracle/admin/SDTEST01/bdump/alert_SDTEST01.log
+ BDUMP=/opt/app/oracle/admin/SDTEST01/bdump
+ CDUMP=/opt/app/oracle/admin/SDTEST01/cdump
+ UDUMP=/opt/app/oracle/admin/SDTEST01/udump
+ OSCRIPTS=/opt/app/oracle/scripts
+ TNS_ADMIN=/var/opt/oracle

+
PATH=/usr/ccs/bin:/opt/app/oracle/product/9.2.0.4/bin:/opt/app/oracle/produc t/9.2.0.4:/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sony-bin:/ usr/local/etc:/usr/ucb:/usr/bin/X11:/usr/dt/bin:/usr/openwin/bin:/opt/SUNWsp ro/bin:/usr/ccs/bin:.
+
LD_LIBRARY_PATH=/opt/app/oracle/product/9.2.0.4/lib:/opt/app/oracle/product/ 9.2.0.4/jdbc/lib:/usr/openwin/lib:/usr/dt/lib:/usr/lib:/lib
+ export LD_LIBRARY_PATHPATH OSCRIPTS UDUMP CDUMP BDUMP INIT ALERT TNS_ADMIN
+ export ORACLE_BASE ORACLE_HOME ORACLE_PATH ORACLE_SID ORACLE_TERM
+ alias alert=tail -500 $ALERT|more
+ PS1=\u@\h_at_SDTEST01>
+ export WARNING_THRESHHOLD=55
+ export CRITICAL_THRESHHOLD=65
+ orastat -ts
+ awk {print $10}
+ grep -vi generic
+ grep -vi pct
+ grep -vi ===
+ grep -vi accurat
+ grep -vi listed
+ export TBS_WARNING=


62.8
61.0
34.4
22.4
11.9
9.9
3.8
0.1
0.0
0.0

0.0
0.0

0.0
+ orastat -ts
+ awk {print $10}
+ grep -vi generic
+ grep -vi ===
+ grep -vi pct
+ grep -vi accurat
+ grep -vi listed
+ export TBS_CRITICAL=

62.8
61.0
34.4
22.4
11.9
9.9
3.8
0.1
0.0
0.0

0.0
0.0

0.0
+ export CHK_TBS_WARNING=

62.8
61.0
34.4
22.4
11.9
9.9
3.8
0.1
0.0
0.0

0.0
0.0

0.0 55
+ export CHK_TBS_CRITICAL=

62.8
61.0
34.4
22.4
11.9
9.9
3.8
0.1
0.0
0.0

0.0
0.0

0.0 65
+ awk {if ($1 > $2) print $1}
+ echo ----- 62.8 61.0 34.4 22.4 11.9 9.9 3.8 0.1 0.0 0.0 0.0 0.0 -----
0.0 55
+ export CHK_TBS_WARNING_EVAL=
+ awk {if ($1 > $2) print $1}
+ echo ----- 62.8 61.0 34.4 22.4 11.9 9.9 3.8 0.1 0.0 0.0 0.0 0.0 -----
0.0 65
+ export CHK_TBS_CRITICAL_EVAL=
+ [ -gt 65 ]

./check_tbs.sh[18]: test: argument expected
+ [ -gt 55 ]

./check_tbs.sh[20]: test: argument expected

Thanks for any further ideas and assistance! - David

-----Original Message-----
From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Darrell Landrum
Sent: Tuesday, June 08, 2004 8:55 PM
To: oracle-l_at_freelists.org
Subject: Re: awk question

Here is an example of one idea, although there may be a cleaner way. I've used an ls -l command to get a particular file size instead of the orastat in your code, then compare that to a previously defined threshold. Basically, I take the threshold and the ls result and concat them into one variable with a space in between. Then, send that value into your awk statement for the test of $1 to $2.

hp19:/home/dlandrum $ cat ak

export WARNING_THRESHHOLD=10

export TBS_WARNING=`ls -l test.ksh| awk '{print $5}'`

export CHK_TBS_WARNING="$TBS_WARNING $WARNING_THRESHHOLD"

echo $CHK_TBS_WARNING | awk '{if ($1 > $2) print $1}'

hp19:/home/dlandrum $ ksh -x ak
+ export WARNING_THRESHHOLD=10
+ awk {print $5}
+ ls -l test.ksh
+ export TBS_WARNING=21
+ export CHK_TBS_WARNING=21 10
+ echo 21 10
+ awk {if ($1 > $2) print $1}

21


Can someone please fill me in on if and how I can use the commented out threshhold variables(after uncommenting) and reference those variables in my awk test/evaluation in place of the hardcoded values($10 > 55 or 65). Thanks
- David

#!/bin/ksh

SID=$1
cd /m1/homes/oracle
. ./$SID #export WARNING_THRESHHOLD=55
#export CRITICAL_THRESHHOLD=65

export TBS_WARNING=`orastat -ts | awk '{if ($10 > 55) print $10}' | grep -vi generic | grep -vi pct | grep -vi === | gr ep -vi listed | grep -vi accurat`
export TBS_CRITICAL=`orastat -ts | awk '{if ($10 > 65) print $10}' | grep -vi generic | grep -vi pct | grep -vi === | g rep -vi listed | grep -vi accurat`

echo $TBS_WARNING
echo $TBS_CRITICAL

if [ $TBS_CRITICAL -gt 65 ]; then

        ./orastat -ts|mailx -s "TBS CRITICAL for $SID" dgreen_at_soe.sony.com elif [ $TBS_WARNING -gt 55 ]; then

        ./orastat -ts|mailx -s "TBS WARNING for $SID" dgreen_at_soe.sony.com fi



Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

___________________________________________________________________________ 


This email and any attached to it are confidential and intended only for the
individual or entity to which it is addressed.  If you are not the intended
recipient, please let us know by telephoning or emailing the sender.  You
should also delete the email and any attachment from your systems and should
not copy the email or any attachment or disclose their content to any other
person or entity.  The views expressed here are not necessarily those of
Churchill Insurance Group plc or its affiliates or subsidiaries. Thank you. 

Churchill Insurance Group plc.  Company Registration Number - 2280426.
England. 

Registered Office: Churchill Court, Westmoreland Road, Bromley, Kent BR1
1DP. 


----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request_at_freelists.org
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------
Received on Thu Jun 10 2004 - 03:49:13 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US