Confirmation of site or host service status

0

I set up this script to run under Linux, but it is not working the way I expected it to be.

I'm using curl to find the state of the HTTP connection.

It returns me:

HTTP/1.1 200 OK
Mais alguns conteúdos do site http...

This is the script:

#!/bin/bash
curl-v --head --output /dev/null http://site:port/folder >> relatorios.txt
if ! HTTP_CODE=200 do
echo "operando servico web"; then
echo "Serviço Online"
else
echo "Serviço Offline"
exit 1
fi
exit

I was expecting it to respond with online service code 200 when it is operating on the network, and offline service with any other code that is termed when a web page is not available, 404, 500 etc.

I turned off the test machine to validate if the message would appear offline but still show online. I would need it to show me the status when it is OK and if for any other reason the page goes out of the air, report that the page is out. I would like to use this result field HTTP/1.1 200 OK because it changes when the page is out.

I made this script on the terminal with vi , I'd like to use curl to check the status of the webpage, but it did not work out as expected. Anyone have any suggestions?

    
asked by anonymous 12.11.2018 / 20:39

2 answers

1

You can use this:

#!/bin/bash

HTTP_CODE=$(curl -o relatorios.txt  -L -s -w "%{http_code}" http://www.yoursite.com/pagina.html)

if [ "$HTTP_CODE" == "200" ]; then
        echo "operando servico web"
        echo "Serviço Online"
else
        echo "Serviço Offline"
        exit 1
fi
    
13.11.2018 / 13:57
0

aki a handy example! I can not format the text on this site sorry! more should help with your problem!

status = $ (curl -s -head google.com | awk '$ 2 ~ "200"')

if [-n "$ status"]; then

echo "operating web service"

echo "Online Service"

else

echo "Offline Service"; exit 1

fi

exit

    
13.11.2018 / 13:46