Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to detect whether the server is connected to the network in Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to detect whether the server is connected to the network in Linux, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

Linux detects whether the server is connected to the network

Abstract: check whether the server is connected to the network every 5 minutes, if there is no network after three tests. The machine is automatically turned off! Main usage scenarios: because you have a server in your remote hometown, you may encounter the problem of network outage caused by a power outage, and the use of UPS is limited after a power outage. Therefore, this script is designed to solve various problems caused by a sudden power outage of the server. When the network goes down after a power outage, the server needs to be shut down automatically. Of course, you need to start the server manually after an incoming call!

#! / bin/bash# detects whether the server is connected to the network If the network does not work, shut down the computer # crontab-e# / 5 *. / check.shecho "Starting test network was clear..." if test-e. / checkInfo then echo "CheckInfo File Exist..." else cat / dev/null >. / checkInfofilast_res= `head-1. / ch eckInfo`checkInternet () {ping_res=1 for url in "8.8.8" 61.139.2.69 "" 114.114.114.114 "" 168.95.1.1 "" 223.5.5.5 "" 180.76.76.76 "do echo" PING ${url} "ping= `ping-c 3 ${url} | awk 'NR==7 {print $4}' `if [${ping}-eq 0] then ping_res=1 else ping_res=2 fi if [${ping_res}-eq 2] then break fi done return ${ping_res} checkInternetresult=" $? "if [${result}-eq 1] then if [ "${last_res}" = "1"] then echo "2" >. / checkInfo elif ["${last_res}" = "2"] then cat / dev/null >. / checkInfo init 0 else echo "1" >. / checkInfofi else cat / dev/null >. / checkInfofi thank you for reading this article carefully I hope the article "how to detect whether the server is connected to the network in Linux" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report