need help generating this output

need to check hardware error are zero

iostat -en |awk '{ if ( $2 == 0 ) { print "      " }  else { print " Hardware errors "} }

can someone please tell me whats wrong with this[COLOR="\#738fbf"]

---------- Post updated at 10:19 PM ---------- Previous update was at 10:16 PM ----------

iostat -en
  ---- errors ---
  s/w h/w trn tot device
    2   0   0   2 c1t0d0
    3   0   0   3 c0t0d0
    2   0   0   2 c1t2d0
    0   0   0   0 c4t600A0B80005A4D130000039F4A4689B8d0
    0   0   0   0 c4t600A0B80005A4D15000003954A468A59d0
    2   0   0   2 c4t600A0B80005A4D13000003A14A468B24d0
    2   0   0   2 c4t600A0B80005A4D15000003964A468BE9d0
    2   0   0   2 c4t600A0B80005A4D13000003A24A468C64d0
    2   0   0   2 c4t600A0B80005A4D15000003974A468E29d0
    2   0   0   2 c4t600A0B80005A4D13000003A34A468EDCd0
    0   0   0   0 c4t600A0B80005A4D15000003994A468F7Fd0

Hi,

there is a single quote missing at the end of your command.
Try:

iostat -en | awk '/^[0-9]/{if ($2 != 0 ) print "Hardware errors"}'

HTH Chris

i need to print errors instead of the hardware errors can someone help

hi its not working it doesnot generate any ouput can u help

sh: iostat: cannot execute

iostat -en  |awk '{print $0, ($2)?X:"Hardware errors"}'

If the iostat output like this:

iostat -en
  ---- errors ---
  s/w h/w trn tot device
    2   0   0   2 c1t0d0
    3   0   0   3 c0t0d0
    2   0   0   2 c1t2d0
    0   0   0   0 c4t600A0B80005A4D130000039F4A4689B8d0
    0   0   0   0 c4t600A0B80005A4D15000003954A468A59d0
    2   0   0   2 c4t600A0B80005A4D13000003A14A468B24d0
    2   123   0   2 c4t600A0B80005A4D15000003964A468BE9d0
    2   234   0   2 c4t600A0B80005A4D13000003A24A468C64d0
    2   0   0   2 c4t600A0B80005A4D15000003974A468E29d0
    2   0   0   2 c4t600A0B80005A4D13000003A34A468EDCd0
    0   0   0   0 c4t600A0B80005A4D15000003994A468F7Fd0

the awk ouput is:

  ---- errors ---
  s/w h/w trn tot device
    2   0   0   2 c1t0d0 Hardware errors
    3   0   0   3 c0t0d0 Hardware errors
    2   0   0   2 c1t2d0 Hardware errors
    0   0   0   0 c4t600A0B80005A4D130000039F4A4689B8d0 Hardware errors
    0   0   0   0 c4t600A0B80005A4D15000003954A468A59d0 Hardware errors
    2   0   0   2 c4t600A0B80005A4D13000003A14A468B24d0 Hardware errors
    2   123   0   2 c4t600A0B80005A4D15000003964A468BE9d0
    2   234   0   2 c4t600A0B80005A4D13000003A24A468C64d0
    2   0   0   2 c4t600A0B80005A4D15000003974A468E29d0 Hardware errors
    2   0   0   2 c4t600A0B80005A4D13000003A34A468EDCd0 Hardware errors
    0   0   0   0 c4t600A0B80005A4D15000003994A468F7Fd0 Hardware errors

nope i just want to check only if $2 is zero.print just the h/w errors

iostat -en |awk '{ if ( $2 == 0 ) { print "      " }  else { print " Hardware errors "} }
 iostat -en | awk '{print ($2)?"Hardware errors":X}' 
iostat -en | awk '{print ($2)?"Hardware errors":X}'
Hardware errors
Hardware errors
s/w h/w trn tot device
    2   0   0   2 c1t0d0
    3   0   0   3 c0t0d0
    2   0   0   2 c1t2d0
    0   0   0   0 c4t600A0B80005A4D130000039F4A4689B8d0
    0   0   0   0 c4t600A0B80005A4D15000003954A468A59d0
    2   0   0   2 c4t600A0B80005A4D13000003A14A468B24d0
    2   0   0   2 c4t600A0B80005A4D15000003964A468BE9d0
    2   0   0   2 c4t600A0B80005A4D13000003A24A468C64d0
    2   0   0   2 c4t600A0B80005A4D15000003974A468E29d0
    2   0   0   2 c4t600A0B80005A4D13000003A34A468EDCd0
    0   0   0   0 c4t600A0B80005A4D15000003994A468F7Fd0

even though its zero its showing hardware errors?

---------- Post updated at 01:08 AM ---------- Previous update was at 01:06 AM ----------

thats not the kind of O/p i want as said before i am trying to check if the device has any hardware errors or not

Ok, paste your expect O/P here.

device has 4 hardware errors,i have to check if h/w coloumn has zero in it and if there are more errors then that particular device has hardware errors.thanks again

example
c4t600A0B80005A4D130000039F4A4689B8d0 has 5 errors

but we can't get your result from your sample data.

What 's meaning of 5 erros? where do you get it?

iostat -en |awk '{ if ( $2 == 0 ) { print "      " }  else { print " Hardware errors "} }

does $2 check the entire coloumn if everything is zero.from the O/p you pasted

incase there are any error it should print that device has errors

iostat -en | awk '/^[0-9]/{if ($2 != 0 ) print "Hardware errors"}'

use to work before but now its not working anymore dont know why please help