Use of curl command under linux

This blog post is a linux study note, only for learning.

Learning blog address: click to open the link

==================================================

Today, in the process of reading the shell script to monitor the tomcat shutdown and automatic restart, I saw a curl command as follows

curl -s -o $GetPageInfo -m 10 --connect-timeout 10 $WebUrl -w %{http_code}   

The specific function is to access the page and save the page content and return the status code.

The parameter functions are as follows:


-s --silent silent mode, that is, do not display errors and progress
-o $GetPageInfo save the file locally and name it $GetPageInfo  
-m indicates the maximum time to fetch a web page (maximum allowable time for data transfer)
-m 10 means that if the operation of obtaining the source code of the webpage cannot be completed within 10 seconds, give up
--connect-timeout connection timeout
--connect-timeout 10 means give up if it can't connect within 10 seconds
$WebUrl is the page path variable we want to visit
-w The -w parameter of curl we can customize the output of curl, %{http_code} represents the http status code


Tried to use it 
curl -s http://www.baidu.com -w %{http_code}

command, the return result is as follows



In the shell script, you can determine whether the service is normal by accessing the status code returned by a single file in the tomcat directory. If the return code is not 200, restart the tomcat service.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326860732&siteId=291194637