Question

I am trying to execute below script,

  data=$(printf "%s " $(find output.log -type f  -exec grep 'ACTIVE\| NOT ACTIVE' {} \; | awk '{print $1}'))
    status=`find output.log -type f  -exec grep 'ACTIVE\| NOT ACTIVE' {} \; | awk '{print $3}'`

    case "$data" in
    ("Instance1")

            echo "Status for Instance1 is : $status";
       ;;
    ("Instance2")

            echo "Status for Instance2 is : $status";
       ;;
    "") echo "empty things"
    ;;
    esac

but it is not showing any output.. maybe i am missing something in my script (may be lot)

The logfile I am using in above script is ie. output.log,

INSTANCE_NAME    OPEN_STATUS       STATUS 
---------------- ------------ ----------------- 
Instance1    OPEN           ACTIVE 

Instance2    OPEN           NOT ACTIVE

Can anyone tell me what is wrong with above script ?

Thanks,

Was it helpful?

Solution

You don't loop over your entries, thus you never have a data "Instance1" but "Instance1 Instance2". You probably want something as the following:

items=$(grep -0 'ACTIVE\| NOT ACTIVE' output.log | tr -s ' ' )
IFS=$'\r\n'
for it in $items; do
  data=$(echo $it | cut -d ' ' -f1 )
  status=$(echo $it | cut -d ' ' -f3- )
  case "$data" in
    ("Instance1")
    echo "Status for Instance1 is : $status";
       ;;
    ("Instance2")
        echo "Status for Instance2 is : $status";
       ;;
    "") echo "empty things"
    ;;
  esac;
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top