Skip to content

Instantly share code, notes, and snippets.

@yorch
Last active October 16, 2016 17:30
Show Gist options
  • Save yorch/aeb4aa1f0f190eadce414e5ade4a9fec to your computer and use it in GitHub Desktop.
Save yorch/aeb4aa1f0f190eadce414e5ade4a9fec to your computer and use it in GitHub Desktop.

Revisions

  1. yorch revised this gist Oct 16, 2016. No changes.
  2. yorch created this gist Oct 16, 2016.
    30 changes: 30 additions & 0 deletions network_monitor.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/bin/bash

    HOST=www.google.com

    while true ; do
    if ifconfig wlan0 | grep -q "inet addr:" ; then
    #$printf "WLAN connected, IP: %s\n" $(hostname -I)
    sleep 60
    else
    echo "Network connection down! Attempting reconnection."
    # First try
    ifconfig wlan0 down
    sleep 3
    ifconfig wlan0 up
    sleep 10
    iwconfig wlan0 essid any
    sleep 10
    ping -c 1 -W 10 $HOST &>/dev/null
    if [ $? -eq 0 ]; then
    exit
    else
    # Second try
    service networking restart
    iwconfig wlan0 essid any
    sleep 10
    ping -c 1 -W 10 $HOST &>/dev/null
    fi
    sleep 30
    fi
    done