[英]How to get the exact status code when checking connectivity between two servers in Linux using wget?
We have new Linux DB servers. 我们有新的Linux DB服务器。 I am writing a script to check the connectivity from our servers to new DB servers.
我正在编写一个脚本来检查从我们的服务器到新数据库服务器的连接。 Based on the exit status code, I wrote my script to give an output if it is connected/connection refused or connection timed out.
根据退出状态代码,我编写了脚本以给出连接/连接被拒绝或连接超时的输出。
All our servers dont have telnet, so I have to check with wget
. 我们所有的服务器都没有telnet,因此我必须使用
wget
进行检查。
Ny sample code to capture the status: Ny个示例代码捕获状态:
m=`echo $?`
if [ $m -eq 124 ]; then
b="Connection Timed Out"
else
if [ $m -eq 6 ]; then
b="Connected"
else
if [ $m -eq 0 ]; then
b="Connected"
else
if [ $m -eq 4 ]; then
b="Connection Refused"
But for new Linux DB servers, we are getting a different status code as 258, even though it is showing as connected: 但是对于新的Linux DB服务器,即使显示为已连接,我们也会得到一个不同的状态代码258。
--2019-09-18 09:53:14-- http://xxx:80/
Resolving xxxxx... xxx
Connecting to xxxx|xxxx|:80... connected.
HTTP request sent, awaiting response...
echo $?
258
This is now misleading even though it has connectivity. 现在,即使具有连接性,这也会产生误导。 Kindly suggest how we can get the exact status.
请提出我们如何获得确切的身份。
You could use the HTTP status codes for checks. 您可以使用HTTP状态代码进行检查。
DB_STATUS_RESPONSE="$(wget --spider --server-response http://ipecho.net/plain 2>&1 | awk '/^ HTTP/{print $2}')"
if [ $DB_STATUS_RESPONSE -eq 200 ]; then b="Connected"; fi
$ echo $b
Connected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.