Score:3

How to determine if the wifi is disconnected from the command line?

cn flag

Ubuntu version: 20.04
Shell: bash
Kernel version: 5.8.0-53-generic #60~20.04.1-Ubuntu

I have a PC which runs a cryptocurrency workload 24/7, and it must be connected to wifi. I have noticed that at least once in a day, the wifi goes down and it does not automatically reconnect. The wifi icon just goes off with a question mark as shown below.

Wifi icon with question mark sign

I have to manually run a network-manager restart (as shown below) to fix the issue.

sudo service network-manager restart

Until I find a permanent fix I am thinking a running a script every 5 minutes which will check if the wifi is down, and if it is down it will run a network-manager restart. How do I determine if the wifi is down from command line?

FedKad avatar
cn flag
Did you try `tail`ing the `/var/log/syslog` file for an appropriate message?
24601 avatar
in flag
anything [here](https://www.cyberciti.biz/faq/how-to-check-network-adapter-status-in-linux/) which helps?
chili555 avatar
cn flag
I would much rather diagnose and fix why it's dropping. Welcome to Ask Ubuntu.
RonJohn avatar
cn flag
WiFi is **never** connected to the command line.
Score:4
cn flag

Failing to find another solution, you can try something similar to this:

tail -f /var/log/syslog | grep --line-buffered ' wlo1: CTRL-EVENT-DISCONNECTED ' \
| while read line
do
  echo "Caught: $line"
  echo "Restarting network-manager..."
  sudo service network-manager restart
done

You can modify the string in grep to something that matches your system.

Score:4
br flag

The command-line tool nmcli has a connectivity check with the below command:

    nmcli networking connectivity

From man pages

   connectivity [check]
       Get network connectivity state. The optional check argument tells NetworkManager to
       re-check the connectivity, else the most recent known connectivity state is displayed
       without re-checking.

       Possible states are:

       none
           the host is not connected to any network.

       portal
           the host is behind a captive portal and cannot reach the full Internet.

       limited
           the host is connected to a network, but it has no access to the Internet.

       full
           the host is connected to a network and has full access to the Internet.

       unknown
           the connectivity status cannot be found out.

When you run nmcli networking connectivity command, it returns any of the below values:

none, portal, limited, full, unknown

You can prepare your script according to the value you required.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.