Todd Wyndham

Forum Replies Created

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • in reply to: AIX awk code fragment help #61745
    Todd Wyndham
    Participant

      IN=prod

      for FS in `lsvg -l ${IN}vg | awk ‘$2 == “jfs” {print $NF}’` ; do

        LV=`lsvg -l ${IN}vg | awk -v FLB=$FS ‘$NF == FLB {print $1}’`

        fuser -k /dev/$LV

        fuser -k /dev/$LV

        fuser -k /dev/$LV

        umount $FS

      done

      varyoffvg ${IN}vg


      Example input data:

        $ lsvg -l prodvg

        prodvg:

        LV NAME             TYPE       LPs   PPs   PVs  LV STATE      MOUNT POINT

        sites2lv            jfs        257   514   2    open/syncd    /sites2

        loglv01             jfslog     1     1     1    closed/syncd  N/A

        apache2_lv          jfs        10    20    2    closed/syncd  /apache2

        eng2log01           jfslog     1     1     1    open/syncd    N/A


      `lsvg -l ${IN}vg | awk ‘$2 == “jfs” {print $NF}’` –>>

        awk defaults to field (column) separator of space

        $2 == “jfs” –>> test input field # 2 to string “jfs”, so it is looking at the TYPE column

        $NF –>> NF means the total number of fields found from the currently inputted line/record read in;

                 but placing a “$” sign in front of the variable NF means,

                 look at a given field in the inputted line/record,

                 thus in this example {print $NF} says to print the value of field # 7

      output from exampled lsvg input above:

        /sites2

        /apache2

      so the for loop becomes:

        for FS in /sites2 /apache2 ; do …


      LV=`lsvg -l ${IN}vg | awk -v FLB=$FS ‘$NF == FLB {print $1}’` –>>

        -v FLB=$FS –>> create the variable FLB with the value from the for loop; first time through, FLB equals /sites2

        ‘$NF == FLB {print $1}’ –>> for each inputted line, test the last input field of the currently read line/record with the variable FLB; if they are equal, print field number 1 of the current line/record;

                                     translated from first time in the for loop:

                                         ‘/sites2  == /sites2 {print sites2lv}’

                                         ‘N/A      == /sites2 {print loglv01}’

                                         ‘/apache2 == /sites2 {print apache2_lv}’

                                         ‘N/A      == /sites2 {print eng2log01}’


      so, when looping thru the for loop:

        FS = /sites2,  then LV = sites2lv

        FS = /apache2, then LV = apache2_lv

    Viewing 1 replies (of 1 total)