mirror of
https://github.com/edu4rdshl/linuxscripts.git
synced 2026-07-18 07:34:45 +00:00
Use a more accurate way to check internet connection
when using wget, if the DNS resolver service take a long time to answer (minutes for example), the script take the same time to give a answer
This commit is contained in:
parent
5aa7a72223
commit
34fed3676f
1 changed files with 5 additions and 9 deletions
14
rnetworking
14
rnetworking
|
|
@ -6,15 +6,13 @@
|
|||
# Autor: Eduard Toloza
|
||||
|
||||
# Define variables
|
||||
ofile=/tmp/google.txt
|
||||
services='write here the name of the services separated by spaces, example: systemd-networkd systemd-resolved wicd network-manager'
|
||||
services='Put here the service names that you want to restart if internet connection is not available, the services must be sepparated by spaces. Example: systemd-resolved systemd-networkd openvpn'
|
||||
|
||||
#Check if wget is installed
|
||||
if command -v wget > /dev/null; then
|
||||
#Check if ping command is available
|
||||
if command -v ping > /dev/null; then
|
||||
# Check internet connection and if not OK then restart all networking services
|
||||
echo "Testing your connection..."
|
||||
wget -q --tries=1 --timeout=1 https://google.com -O $ofile &> /dev/null
|
||||
if [ ! -s $ofile ]; then
|
||||
if ! ping -q -c 1 -W 1 1.1.1.1 > /dev/null; then
|
||||
echo "Your connection is not working, restarting your network services: $services"
|
||||
sudo systemctl restart $services
|
||||
if [ $? -eq 0 ]; then
|
||||
|
|
@ -22,11 +20,9 @@ if command -v wget > /dev/null; then
|
|||
else
|
||||
echo "An error has occurred, make sure that service names are correct."
|
||||
fi
|
||||
rm $ofile
|
||||
else
|
||||
echo "Your connection is OK"
|
||||
rm $ofile
|
||||
fi
|
||||
else
|
||||
echo "wget is not installed, aborting."
|
||||
echo "ping command is not available, aborting."
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue