Sponsored Content
Full Discussion: Problem evaluating condition
Top Forums Shell Programming and Scripting Problem evaluating condition Post 303011947 by edstevens on Friday 26th of January 2018 10:02:04 AM
Old 01-26-2018
Problem evaluating condition

First, given this bit of code (line numbers included for reference:
Code:
 59 get_all_db () {
 60 #echo getting all db
 61 dblist=`egrep -i "product/12" /etc/oratab |grep -v "listener"|\
 62       awk -F\: '{print $1}'|sort`
 63 echo list is $dblist
 64 echo
 65 echo
 66 echo "INSTANCE_NAME    HTTPS Port  HTTP Port"
 67 echo "---------------- ---------- ----------"
 68 for ORACLE_SID in $dblist
 69 do
 70 echo checking for pmon_$ORACLE_SID
 71 ps -ef|grep pmon_$ORACLE_SID|grep -v grep
 72 echo ps command complete
 73   if ps -ef|grep pmon_$ORACLE_SID|grep -v grep
 74   then
 75     echo calling sqlplus
 76     . oraenv
 77     sqlplus -s /nolog <<EOF
 78     set echo off feedback off verify off head off
 79     conn / as sysdba
 80     select instance_name,
 81            DBMS_XDB_CONFIG.gethttpsport "HTTPS Port",
 82            DBMS_XDB_CONFIG.gethttpport "HTTP Port"
 83     FROM v\$instance;
 84 EOF
 85   fi
 86 done
 87 }

Producing this output:
Code:
  1 list is db12 fs91upg fs92dev fs92upg hr92dev hr92tst hr92upg
  2
  3
  4 INSTANCE_NAME    HTTPS Port  HTTP Port
  5 ---------------- ---------- ----------
  6 checking for pmon_db12
  7 ps command complete
  8 checking for pmon_fs91upg
  9 ps command complete
 10 checking for pmon_fs92dev
 11 ps command complete
 12 checking for pmon_fs92upg
 13 ps command complete
 14 checking for pmon_hr92dev
 15 ps command complete
 16 checking for pmon_hr92tst
 17 ps command complete
 18 checking for pmon_hr92upg
 19 ps command complete

What I don't understand is why the IF continues to evaluate FALSE. The first iteration of the DO loop, where the value of $ORACLE_SID is 'db12' should evaluate false, but the rest are true. To help debug I added lines 70 and 71 to show the current value of ORACLE_SID and the result of the same command that produces the result to be evaluated by the IF. You can see from the output that it appears to always return null (false) but if I execute the very same command manually, it returns the expected result:

Code:
  1 oracle:fs91upg$ echo $ORACLE_SID
  2 fs91upg
  3
  4 oracle:fs91upg$ ps -ef|grep pmon_$ORACLE_SID|grep -v grep
  5 oracle    2842     1  0 Jan22 ?        00:00:34 ora_pmon_fs91upg
  6
  7 2018-01-26 08:59:44
  8 oracle:fs91upg$


Last edited by edstevens; 01-26-2018 at 11:49 AM.. Reason: Adding reference line numbers to block of code
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problem with if condition

hi, :) pls consider the following if statement if //g') ] then ........ else ....... when i execute the script i am getting the following error '(' unexpected I am not able to find the mistake. could anybody tell where i did mistake. cheers RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies

2. Shell Programming and Scripting

problem in if condition

hi, actully i need the belp for the below. host_list=" Host1 host2 host3 host4 " n=`hostname` i need to put the condition like the below if n is among the host mention in the host_list if then #some stugg else # some other stuff fi (1 Reply)
Discussion started by: mail2sant
1 Replies

3. Shell Programming and Scripting

problem in if then else condition

Hi , I am trying the following simple script . But it is always giving 1 output. Dont know why #!/bin/sh find . -name "a.log" if ; then echo "1" else echo "0" fi Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies

4. Shell Programming and Scripting

Problem in using AND OR condition together

a=rhino b=crocodil c=testsc if && "$c" = testsc ] then echo "Test #5 succeeds." else echo "Test #5 fails." fi i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Discussion started by: gokulraj23
11 Replies

5. Shell Programming and Scripting

if condition not evaluating as expected

Hi all, Thanks in advance for your time. I have a data file like this: 1 7.465753425 2 8.980821918 1 1.717808219 1 6.550684932 0 5.432876712 I wish to write a bash script to check both columns and output a 1 if col1==1 AND col2<3. Otherwise I want to output a 0. In the above... (5 Replies)
Discussion started by: jem8271
5 Replies

6. Shell Programming and Scripting

If condition problem

Hi, I need to use if condition for search a file pattern on a particular location. cd $file_Path if || then do this else do that fi Can someone help me with the if part, how i can put those conditions? make sure format should be *.file* and *.file file is a keyword which i... (5 Replies)
Discussion started by: amit.mathur08
5 Replies

7. Shell Programming and Scripting

problem with if condition

Hi, I'm writing a bash script and i have a condition that goes if then break fi but, when i go to run it, i come across this line 10: ' where line 10 is the if I don't know what's going on :( (2 Replies)
Discussion started by: channyboy
2 Replies

8. Shell Programming and Scripting

Problem in if condition

Hi, below is the script in ksh and i am having issues with if condition. It takes in one argument as input and executes the shell script. The problem is in if condition in shell script. If input is given as 1 it works out well. But if input is given as 2 or something else the script is failing to... (1 Reply)
Discussion started by: abhi_123
1 Replies

9. Shell Programming and Scripting

If condition problem

Hi All, I am using below if condition to check whether null is passed as a parameter to the program if or ; then echo "ABC">>$FILE else echo "CDF">>$FILE fi However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies

10. Shell Programming and Scripting

Condition problem

Hi All, Seeking for your assistance on how to condition it correctly. cat file1.txt 290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00 290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00 290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00 1st scenario: if the fourth column contains 888s and 0s it is by... (16 Replies)
Discussion started by: znesotomayor
16 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 05:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy