Easy and simple questin about he curl commands found here:
sensor:
# If this sensor returns anything other than 200, there's a problem with Plex!
# Scans every 10 minutes
- platform: command_line
name: Plex HTTP Code
command: curl -I http://192.168.1.X:32400/web/index.html 2>/dev/null | head -n 1 | cut -d$' ' -f2
scan_interval: 600
I have tested it, and it works, no problem. But I have looked for a explanation for the parameters, and can’t realy find it.
Can anyone explain this? → 2>/dev/null | head -n 1 | cut -d$’ ’ -f2
2>
redirects any error output. /dev/null
says basically throw it away. I do not want to see that!
|
is the pipe character used to do something to the output of the curl
command.
head -n 1
uses the head
command to just select the fist line of the output and discard anything else/
cut -d$’ ’ -f2
uses the cut
command using the space character as a field delimiter. It outputs only the second field (everything between the first & second space characters).
So this question was about your Linux shell, the head
command, and the cut
command.
Sometimes knowing what to search for is half the battle
2 Likes
Very good and informative answer, now I see how it works:)
1 Like
I was hoping it was clear. Sometimes when you know something so well it is difficult to explain to others,
I have been a UNIX administrator for many years.