A small script that I use as a startup to welcome me and let me know if there is or isn't internet connectivity.
Code: Select all
#!/bin/bash
# May be reduced from default of 18 seconds to 15 or less if using an SSD or fast HD.
# Also if using a static IP rather than DHCP.
# I've used 10 here, but it seems long to me in every pup I've used it on.
sleep 10
# Establish some string variables
# Change "Earthling" to your name or use the $USER system variable if you like.
# Example _yourname="John Doe" or _yourname=$USER
_yourname="Earthling"
_diamsg=""
_tb="Testing Connectivity"
_day="Today is `date +%A`"
# Establish some numerical variables
_hour=`date +%H`
_ret=252
if [ $_hour -ge 00 -a $_hour -le 11 ]
then
_tod="Good morning, "
elif [ $_hour -ge 12 -a $_hour -le 17 ]
then
_tod="Good afternoon, "
else
_tod="Good evening, "
fi
# Concat the strings less internet status
_diamsg=$_tod"$_yourname"". "$_day" and..."
# Test if internet is active and connected
wget -q --spider http://google.com; _Ucon=$?
if [ $_Ucon -eq 0 ]
then
_diamsg=$_diamsg" Internet access is confirmed. "
else
_diamsg=$_diamsg"--- WARNING: No Internet Connection ---"
fi
# Loop until the Awesome button has been selected
while [ $_ret -ne 0 ]
do
# Open dialog
yad --width=600 --center --fixed --on-top \
--image="dialog-exclaimation" \
--buttons-layout=center \
--button="Awesome:0" \
--text-align=center --title="$_tb" \
--text-align=center --text="$_diamsg" \
_ret=$?
done
exit
After I made this screen shot I realized that $? would always be 0 and inform me that there was internet, whether or not there actually was internet connectivity.
I've corrected the script to concat the strings BEFORE the internet check to avoid the issue. Code SHOULD be correct now.
I've also discovered that the code I was using was NOT the proper way to test for internet connectivity. That has been corrected as well.
Turns out the way to determine if internet connectivity exists that is depicted in the screen shot is valid as long as netcat is installed, which it wasn't on my system.
Oh well. Live and learn.