lundi 3 mai 2021

use if condition in awk

# fetch data guard standby database names to get its property values
  to run across multiple databases
    exec &> /tmp/output.log
    dgmgrl / <<EOF
      show configuration verbose;
    EOF
    for XB in $(egrep 'Primary|Physical|Logical' /tmp/dg_output.log |sort |awk -F" " '{print $3 $1}'); do
      if [[ "$(echo "$XB"|awk '{print substr($1,1,7)}')" == "Primary" ]]; then
      PRIMARY=$(echo "$XB"|awk '{print substr($1,8)}')
      fi
     if [[ "$(echo "$XB"|awk '{print substr($1,1,8)}')" == "Physical" ]]; then
      STANDBY=$(echo "$XB"|awk '{print substr($1,9)}')
      fi
    done
    dgmgrl / <<EOF
      show database verbose $PRIMARY;
      show database verbose $STANDBY;
    EOF

Here, at line 10, if I get single value for physical, then I'm able to assign required substring value to standby.

But when I get multiple entries for word 'Physical' (at line 10) then I'm not able to assign $STANDBY for the second value.

If there are more than one value from the output of line 10

 (if [[ "$(echo "$XB"|awk '{print 
    substr($1,1,8)}')" == "Physical" ]]; then) 
    
    then I want like below:
    
    $STANDBY1=xyz
    $STANDBY2=abc
    
    and the use above variables in STANDBY1 STANDBY1
    
    
      dgmgrl / <<EOF
      show database verbose $PRIMARY;
      show database verbose $STANDBY1;
      show database verbose $STANDBY1;
     EOF

Aucun commentaire:

Enregistrer un commentaire