1

here are my variables:

HEADER='Device     bps     tps     bread     bwrtn'
HEADERIZE="BEGIN {print \"$HEADER\"}"
PRINTF='{printf "%-10s  %11s  %11s  %12s  %12s  %13s  %13s  %13s\n", device, bps, tps, bread, bwrtn}'
CMD='iostat -DlR 1 2'
FILTER='/^cd/ {next} /^Disks:/ {reportOrd++; next} (reportOrd<2) {next}'
FORMAT='{device=$1; bps="?"; tps="?"; bread=$5; bwrtn=$6}'

$CMD | awk "$HEADERIZE $FILTER $FORMAT $PRINTF"  header="$HEADER"

I want the output to look like this:

Device     bps     tps     bread     bwrtn
hdisk0     0.0     0.0     0.0       0.0         
hdisk1     0.0     0.0     0.0       0.0
hdisk2     0.0     0.0     0.0       0.0
hdisk3     0.0     0.0     0.0       0.0

of course I would like more performance headers, but I'm trying to keep it simple.

The problem comes in when I run: $CMD | awk "$HEADERIZE $FILTER $FORMAT $PRINTF" header="$HEADER". It's coming out like this:

Device          bps tps bread bwrtn
---------------            ?            ?  --------------------------------------              
%tm                   ?            ?         bwrtn           rps
act                   ?            ?          outs          serv
hdisk1                ?            ?           0.0           0.0
hdisk0                ?            ?           0.0           0.0

I believe the variable "FILTER" is incorrect but don't know the right syntax.

This is the input: iostat -DlR 1 2

output:

root@myserver #iostat -DlR 1 2

System configuration: lcpu=20 drives=2 paths=16 vdisks=0

Disks:                      xfers                                read                                write                                  queue                  
--------------- -------------------------------- ------------------------------------ ------------------------------------ -------------------------------------- 
                  %tm    bps   tps  bread  bwrtn   rps    avg    min    max time fail   wps    avg    min    max time fail    avg    min    max   avg   avg  serv
                  act                                    serv   serv   serv outs              serv   serv   serv outs        time   time   time  wqsz  sqsz qfull
hdisk1            0.0   0.0    0.0   0.0    0.0    0.0   0.0    0.0    0.0     0    0   0.0   0.0    0.0    0.0     0    0   0.0    0.0    0.0    0.0   0.0   0.0
hdisk0            0.0   0.0    0.0   0.0    0.0    0.0   0.0    0.0    0.0     0    0   0.0   0.0    0.0    0.0     0    0   0.0    0.0    0.0    0.0   0.0   0.0

Disks:                      xfers                                read                                write                                  queue                  
--------------- -------------------------------- ------------------------------------ ------------------------------------ -------------------------------------- 
                  %tm    bps   tps  bread  bwrtn   rps    avg    min    max time fail   wps    avg    min    max time fail    avg    min    max   avg   avg  serv
                  act                                    serv   serv   serv outs              serv   serv   serv outs        time   time   time  wqsz  sqsz qfull
hdisk1            0.0   0.0    0.0   0.0    0.0    0.0   0.0    0.0    0.0     0    0   0.0   0.0    0.0    0.0     0    0   0.0    0.0    0.0    0.0   0.0   0.0
hdisk0            0.0  77.8K  19.0   0.0   77.8K   0.0   0.0    0.0    0.0     0    0  19.0   0.3    0.2    0.5     0    0   0.0    0.0    0.0    0.0   0.0   0.0





Desired output:


Device     bps     tps     bread     bwrtn
hdisk0     0.0     0.0     0.0       0.0         
hdisk1     0.0     0.0     0.0       0.0
hdisk2     0.0     0.0     0.0       0.0
hdisk3     0.0     0.0     0.0       0.0
3
  • It's probably useful to edit the question to show the input text as well as the desired and undesired outputs. Nov 30 '17 at 18:04
  • Your code as it is does not run: sprintf complains for the inconsistent number of parameters. Please review and test your the code before posting it.
    – simlev
    Apr 18 '18 at 15:06
  • My iostat does not know options -DlR. What system/version are you on?
    – simlev
    Apr 18 '18 at 15:13
0

Solution:

iostat -d 1 2 | awk 'BEGIN{print "Device\tbps\ttps\tbread\tbwrtn"}/^hdisk/{print $1"\t"$3"\t"$4"\t"$5"\t"$6}'

Output:

Device  bps     tps     bread   bwrtn
hdisk1  0.0     0.0     0.0     0.0
hdisk0  0.0     0.0     0.0     0.0
hdisk1  0.0     0.0     0.0     0.0
hdisk0  77.8K   19.0    0.0     77.8K

Comments:

I'm afraid you are overcomplicating things. The offered solution is a guess based on your input sample and desired output, which do present some inconsistencies. Please explain where the data for hdisk2 and hdisk3 come from, since they are not present in the input. Please also explain the reason for building such a convoluted solution, that splits the code into several environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.