View Single Post
Posts: 215 | Thanked: 158 times | Joined on Jan 2010
#8
OK, I wrote a bash script that should do the following:

1) check if i'm already connected to the enterprise network. if not...

2) look for the SSID of the enterprise network. if found...

3) disconnect from current connection and connect to enterprise network.

then I will use alarmed to auto-run the script every 10 min or so during business hours.

I haven't fully tested the script yet, but it seems to be working. I'm not really good with bash and never used awk so don't laugh!


Code:
#!/bin/bash

#get current ssid
LIST=$(iwconfig wlan0 | awk -F":" '/ESSID/{print $2}')

#if already connected then quit
if [ $LIST = '"nasa"' ]; then 
    exit 1;
fi

#clear previous ssid scans
rm /home/user/MyDocs/scripts/scans

#if not connected, bring up wlan (if not already) and scan ssids
ifconfig wlan0 up
SCANS=$(iwlist wlan0 scan | awk -F":" '/ESSID/{print $2}')
echo "$SCANS" > /home/user/MyDocs/scripts/scans
GOAL=$(more scans | awk '/"nasa"/{print "1"}' /home/user/MyDocs/scans)

#if network not found, exit
[ "$GOAL" ] || exit

#if network found, disconnect current network and connect to network using dbus
if [ "$GOAL" ]; then
	dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
	sleep 5
	dbus-send --type=method_call --system --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:5f027850-3445-4eef-ac3f-76b423515990 uint32:0
	fi
I would like to modify this code so I don't have to be writing variables out to files, but the fact that its working is enough for now.
 

The Following 4 Users Say Thank You to Flynx For This Useful Post: