#!/bin/bash echo "Scanning available networks for your home WLAN connection..." # The essid of my home wlan is "redbeard" homenet=$(sudo /sbin/iwlist wlan0 scan |grep "ESSID:\"redbeard1\"") # Housekeeping. You'll understand later. if [ -e /home/james/Desktop/Success ] then sudo rm /home/james/Desktop/Success fi if [ -e /home/james/Desktop/Failure ] then sudo rm /home/james/Desktop/Failure fi if [ -z ${homenet} ] then echo "Home network not detected, aborting..." else echo "Connecting to ${homenet}, please wait..." if [ -e /var/run/dhcpcd-wlan0.pid ] then echo "Removing lockfile..." sudo rm /var/run/dhcpcd-wlan0.pid else echo "No dhcpc lock found, continuing..." fi # When I used to use WEP encryption I had the next 3 lines uncommented... echo "Assigning WEP key to the card..." sudo /sbin/iwconfig wlan0 key "0101010101" echo "Key status: $?" echo "Setting essid to \"redbeard1\"" sudo /sbin/iwconfig wlan0 essid "redbeard1" echo "essid status: $?" echo "Obtaining IP address from dhcpcd..." sudo /sbin/dhcpcd wlan0 # This lets me know if the status/result of my script's execution if [ $? == "0" ] then sudo /sbin/ifconfig wlan0 >> /home/james/Desktop/Success else echo $(date) >> /home/james/Desktop/Failure fi echo "dhcpcd status: $?" fi