Hello.
I am trying to write a small script that tests to see what wireless network I am connected to and automatically turning on or off samba sharing.
I want samba to be on while I'm on my own wireless network, but I want it to automatically shut off if I connect to a public network.
The best way I can figure out to do this is by running:
Code:
gksu iwlist ath0 scan | grep "ESSID:"Cafe Wireless""
to see if the public network is in the list (presuming I would be connected to it.)
First question: is there a better way to find out? perhaps:
Code:
gksu iwconfig ath0 | grep "ESSID:"Cafe Wireless""
this would tell me what I'm actually connected to. I am using NetworkManager to deal with the wireless. Is there something I can query in NetworkManager to find this info?
Second question: is gksu appropriate? I want the script to run as non-root user but I want it to pop up a password dialog to shutdown samba if required. I have also heard of gksudo.
Third question: I am having trouble with running a test in the script. Here's what I have:
Code:
if [ -n $(/usr/bin/gksu iwlist ath0 scan | grep "ESSID:"Cafe Wireless"") ] ; then
/usr/bin/gksu /etc/init.d/samba stop
fi
This seems very erratic. I have been testing it here while I am connected to that network but sometimes it shuts down samba and sometimes not. However, iwlist always finds "ESSID:"Cafe Wireless". Is this the correct use of test? or is it more for checking for actual files and whatnot.
Any help would be great.
Thanks!
Ben