Haproxy question AND "or" condition while using AWK

aleksi

New Member
Joined
Dec 14, 2023
Messages
2
Reaction score
1
Credits
27
I have multiple AWK queries I get haproxy metrics value by them
awk -F , '/[keyword]/{print $5}' /tmp/.hastats.tmp
but sometimes the query return no value neither any other messages - just empty string.
How can I improve the query to return any other value if it's sent empty string?


And what value I can use in the above keys to signalize the problems with haproxy metric?
I don't see in /tmp/.hastats.tmp any values except zero or positive integer numbers.
Would I be right if I'll use the negative integer (-1) to problem reporting?
 


Welcome to the forums.

I think the space should be removed between the comma and -F switch for awk. However the target file should have a fifth field, or awk wouldn't be expected to print anything useful.

If the file to search looks anything like this:
Code:
weak,0,1,0,1
beh,0,1,0,2
grak,0,1,0,3
weak,0,1,0,4
beh,1,1,0,5
weak,1,1,6,6
end,0,0,0,0

Then this command line could be used:
Code:
awk -F, -e '/weak/{ if ($5) { print $5 };}' /tmp/.hastats.tmp

REMINDER: there cannot be a space between option for awk and the delimeter.

You will have to be more clear about returning an integer value, what you are trying to achieve with it. Make absolutely sure, after many trials with creating the output file, that the value you choose to return an error doesn't happen.
 
Moving this to Command Line.

If this is a homework or assignment question, you should first consult your text books or help resources, then ask your tutor, teacher of lecturer.

Chris Turner
wizardfromoz
 


Latest posts

Top