W
W
wolverine7772019-06-26 22:12:22
Nagios
wolverine777, 2019-06-26 22:12:22

How to extract a number from the response to write a plugin?

I want to write a plugin for getting status codes (200, 404, etc.)
To do this, I have this line that works)))

curl -I http://www.google.com | grep HTTP; (для гугла например)

I'm thinking of making a script like
If 200 - everything is OK,
If 404 - not OK
#!/bin/bash/

otvet=curl -I http://www.google.com | grep HTTP;

case $otvet in
[200]*)
echo "OK"
exit 0
;;
[404]*)
echo "Not Found"
exit 2
;;
*)
echo "UNKNOWN"
exit 3
;;
esac

The question is - is the idea correct at all, and if so - how to pull out this very tsifir? And that usually happens
[[email protected] plugins]# curl -I http://www.google.com | grep HTTP;
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 200 OK

Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question