Followup: I create a number of bash functions to
handle the task(s). Thank you all for the help!
function GetIP () {
echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk
'{print $9}')"
}
function CheckInternetStatus () {
local GoogleDNS="8.8.8.8";
local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );"
# echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty"
if [[ "$RtnStr" == *", 0% packet loss"* ]]; then
echo "UP"
else
echo "DOWN"
fi
}
function GetPublicIP () {
local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com)
# echo "WIP = <$WIP>" > "/dev/tty"
if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be
reached"* ]]; then
WIP="Not Found"
fi
echo $WIP
}
function GetGW () {
echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print
$2}')"
}
function UpDownedEthernetDevices () {
local State=""
local LinkState=""
for Line in $(nmcli device | grep ethernet | awk '{print $1}'); do
State="$(nmcli device | grep $Line | awk '{print $3}')"
LinkState="$(ip address | grep eno2 | awk -F "," '{print $3}')"
# echo "Line = <$Line> State = <$State> LinkState =
<$LinkState>')" > "/dev/tty"
if [ "$State" == "disconnected" ]; then
echo "Reconnecting $Line" > "/dev/tty"
/usr/bin/nmcli device disconnect $Line
/usr/bin/nmcli device connect $Line
/usr/bin/nmcli connection down $Line
/usr/bin/nmcli connection up $Line
elif [[ $LinkState == "DOWN" ]]; then
echo "Reattaching (link) $Line" > "/dev/tty"
beesu "ip link set $Line down; ip link set $Line up;"
echo "Reconnecting $Line" > "/dev/tty"
/usr/bin/nmcli connection down $Line
/usr/bin/nmcli connection up $Line
fi
done
}
function DisplayStatus () {
NotifySound
local Msg=""
local GW=""
local IP=""
local InternetStatus="$(CheckInternetStatus)"
local PublicIP=""
# if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then
if [ "$InternetStatus" == "UP" ]; then
GW="$(GetGW)"
IP="$(GetIP)"
PublicIP="$(GetPublicIP)"
# Msg+="$InetDev successfully started and is a gateway\n\n"
Msg+="Internet is $InternetStatus\n"
Msg+="IP=$IP\n"
Msg+="gw=$GW\n"
Msg+="Public IP=$PublicIP\n"
echo -e $Msg > "/dev/tty"
zenity --title "$Title Status" --info --text "$Msg" --width=250
else
Msg="Internet ($InetDev) is down"
echo -e $Msg > "/dev/tty"
zenity --title "$Title Status" --info --text "$Msg" --width=200
fi
}
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx