I run the below code
iostat -x 1 2 | sed 's/,/./g' | awk '/^avg-cpu/ {c++; a=2}
c==2 && a && !--a {printf ("%s,%s,%s,", $1, $3, $4)}
c==2 && /^sda/ {printf ("%s,", $14)}
c==2 && /^sdb/ {printf ("%s,", $14)}
c==2 && /^nvme0n1/ {printf ("%s,",$14)}'
in order to get the values of cpu and disk i/o. What I'm now trying to do is a check if there is nvm disk or not. If there is print its util otherwise print -1.00.
I tried
if [ c==2 && /^nvme0n1/ ] then {printf ("%s,",$14)}; else {printf -1.00}'
and I'm getting
awk: cmd. line:5: if [ c==2 && /^nvme0n1/ ] then {printf ("%s,",$14)}; else {printf -1}
awk: cmd. line:5: ^ syntax error
awk: cmd. line:5: if [ c==2 && /^nvme0n1/ ] then {printf ("%s,",$14)}; else {printf -1}
awk: cmd. line:5: ^ syntax error
awk: cmd. line:5: if [ c==2 && /^nvme0n1/ ] then {printf ("%s,",$14)}; else {printf -1}
awk: cmd. line:5: ^ syntax error
and
c==2 && !/^nvme0n1/ {printf ("%s,",1.00)}'
which gives me more than one 1.00, I guess each 1.00 for each time cannot find it.