daily pastebin goal
67%
SHARE
TWEET

wifi-connect.sh

josephxsxn Jun 30th, 2017 (edited) 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #Set the SSID you want to reconnect to when found
  3. timstim=$(date -u)
  4. ssid="AD-INFRA-E1000"
  5. interface="wlan0"
  6. string=$(ifconfig $interface| grep "inet addr:")
  7. if [[ $string == *"inet addr:"* ]]; then
  8.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"CONNECTED\"}]}"
  9. else
  10.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"DISCONNECTED\"}]}"
  11.     echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"SCANNING\"}]}"
  12.     ssidlist=$(sudo iwlist $interface scan | grep ESSID)
  13.     if [[ "$ssidlist" =~ "$ssid" ]]; then
  14.         sudo ifup --force $interface
  15.         sleep 10
  16.         string=$(ifconfig $interface | grep "inet addr:")
  17.         if [[ $string == *"inet addr:"* ]]; then
  18.             echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"RECONNECTED\"}]}"
  19.         else
  20.             echo  "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"UNKNOWN_ISSUE_RECONNECTING\"}]}"
  21.         fi
  22.     else
  23.         echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"SSID_NOT_FOUND\"}]}"
  24.         echo "{\"TIMSTIM\" : \""$timstim"\", \"WIFI\" : [{\"NETWORK_STATE\":\"DISCONNECTED\"}]}"
  25.     fi
  26. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top