-2

i'm triying to understand some program on nagios, it is about counting warnings :

countWarnings=$(/usr/local/nagios/bin/nagiostats | grep "Ok/Warn/Unk/Crit:" | sed 's/[[:space:]]//g' | cut -d"/" -f5)

this is the part of the code i don't get

what is the sed part doing and cut part

i'm new in this kind of programming, really need help

Leoth
  • 1
  • Have you started with `man cut`? Any basic `sed` tutorial will tell you `s` is for text replacement. – miken32 Dec 19 '18 at 02:10
  • 1
    Usually, "please explain this code" questions are considered too broad to be within our rules unless you're **extremely** specific about what you do and don't know -- showing your prior research ("I read `man sed`, but don't understand how the paragraph about *foo* applies to what we're doing here") helps. Right now, an answer would have to go into explaining regular expressions and character classes, which is quite a lot of scope that could be avoided if we knew more precisely what you were having trouble with. – Charles Duffy Dec 19 '18 at 02:10
  • 1
    BTW, have you tried running the pipeline by hand with the last part or two taken off? Comparing output of `/usr/local/nagios/bin/nagiostats | grep "Ok/Warn/Unk/Crit:"` to what you get adding `| sed 's/[[:space:]]//g'` onto the end is a pretty good place to start. – Charles Duffy Dec 19 '18 at 02:11

1 Answers1

0

I know nothing about nagios, but supposing you understand what grep is doing, the rest is:

sed (stream editor) is substituting (erasing) all white spaces for nothing (or a white space, whatever is between the second and third slash '//'), including tabs and linebreaks (this is what [:space:] stands for), globally. This combines to 's/[[:space:]]//g'

The result goes to cut, that will use as delimiter (set with -d) slashes "/" and will select and print only field (-f) 5.

By the way, use code function when showing posting codes to StackOverflow, makes easier to read and answer (for instance, I do not know if you wrote 's/[[:space:]]//g' or 's/[[:space:]]/ /g' just from looking).

Meligordman
  • 75
  • 2
  • 7