iostat & awk shortcuts (snippets for solaris)

-bash-3.00$ iostat -x
                  extended device statistics                   
device       r/s    w/s   kr/s   kw/s wait actv  svc_t  %w  %b 
md10         5.3    5.2  331.3  329.9  0.0  0.0    3.5   0   4 
md11         5.3    0.0  331.3    0.2  0.0  0.0    0.7   0   0 
md12         0.0    5.2    0.0  332.0  0.0  0.0    6.5   0   3 
md13         5.2    5.2  329.8  329.8  0.0  0.0    3.4   0   4 
md14         5.2    0.0  329.8    0.0  0.0  0.0    0.5   0   0 
md15         0.0    5.4    0.0  345.9  0.0  0.0    6.4   0   3 
md16         3.5    3.4  220.8  220.0  0.0  0.0    3.7   0   2 
md17         3.5    0.0  220.8    0.0  0.0  0.0    0.9   0   0 
md18         0.0    3.8    0.0  240.2  0.0  0.0    6.7   0   2 
md22         3.5    3.5  220.0  220.0  0.0  0.0    3.6   0   2 
md23         3.5    0.0  220.0    0.0  0.0  0.0    0.8   0   0 
md24         0.0    3.9    0.0  248.4  0.0  0.0    6.5   0   3 
md25        41.5   41.5 2656.2 2656.2  0.0  0.3    3.6   0  29 
md26        41.5    0.0 2656.2    0.0  0.0  0.0    0.5   0   2 
md27         0.0   48.4    0.0 3099.6  0.0  0.3    6.6   0  32 
sd0         58.9    0.1 3756.0    0.3  0.0  0.0    0.5   0   3 
sd1          0.0   58.7    0.0 3753.5  0.0  0.4    6.6   0  38 
nfs1         0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0

say you needed to add the total outputs of one column –>
iostat -x | grep -v <column name> | awk '{sum+=$x}END{print sum}'

example:

you wanted to add everything in the kr/s (kilobytes read per second) column, the syntax would be:
iostat -x | grep -v kr/s | awk '{sum+=$4}END{print sum}'

where the grep statement removes the column header (in the example the column was kr/s)
the $x statement in awk just chooses the column number (column #4 in my example)

«
»

Leave a Reply

Your email address will not be published. Required fields are marked *