fix: add check_internet.sh
This commit is contained in:
parent
beea227cb3
commit
3ae2a50e93
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Define the file path where the indicator file will be stored
|
||||
indicator_file="./no-internet.txt"
|
||||
|
||||
# URL to ping when internet connection is available
|
||||
ping_url="https://healthchecks.io/ping/{uuid}"
|
||||
|
||||
# Function to check internet connection
|
||||
check_internet_connection() {
|
||||
if ping -q -c 1 -W 1 cloudflare.com >/dev/null 2>&1; then
|
||||
return 0 # Internet connection is available
|
||||
else
|
||||
return 1 # Internet connection is not available
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to perform curl operation with error handling
|
||||
perform_curl() {
|
||||
if curl -fsS -m 10 --retry 5 -o /dev/null "$1"; then
|
||||
echo "Curl to $1 was successful."
|
||||
else
|
||||
echo "Curl to $1 failed with error: $?"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check internet connection
|
||||
if check_internet_connection; then
|
||||
echo "Internet connection is available."
|
||||
# Ping the URL
|
||||
echo "Pinging $ping_url"
|
||||
perform_curl "$ping_url"
|
||||
# Delete the indicator file if it exists
|
||||
if [ -f "$indicator_file" ]; then
|
||||
echo "Deleting the indicator file."
|
||||
rm -f "$indicator_file" 2>/dev/null || echo "Error deleting $indicator_file"
|
||||
fi
|
||||
else
|
||||
echo "No internet connection."
|
||||
# Check if the indicator file exists
|
||||
if [ -f "$indicator_file" ]; then
|
||||
echo "Indicator file found. Waiting for 6 hours before rebooting..."
|
||||
sleep 6h
|
||||
echo "Rebooting now..."
|
||||
sudo reboot
|
||||
else
|
||||
echo "Creating the indicator file and rebooting immediately."
|
||||
touch "$indicator_file" 2>/dev/null || echo "Error creating $indicator_file"
|
||||
echo "Rebooting now..."
|
||||
sudo reboot
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue