![]() |
whereami - Location Detection |
whereami will process the /etc/whereami/detect.conf file in order to find the set of locations you are now in for the configuration stage.
You should read the detect.conf manpage to find out how to do this,
In brief, detect.conf is comprised of lines like:
set INTERFACE eth0 testdhcp '*.*.*.*' dhcp testarp eth0,00:24:5e:17:12:11,10.2.0.4 auckland testarp eth0,00:20:ED:40:66:14,192.168.1.249 ppg testping 172.16.100.2,172.16.100.86 ceo7k
Where each line is in three parts:
<command> <parameter(s)> <location>
default | default location | Set this at the top of your scripts to choose the name of the location to use when all tests fail. |
set | set VARIABLE value | Sets an environment variable. These variables may be referred to within the scripts. Most standard scripts refer to $INTERFACE, for example, to indicate the current interface we are dealing with. |
if | if location[,location...] ... tests ... [elif location[,location...] ... tests ...] [else ... tests ...] fi |
If one of the listed locations has been previously found true, then
the if... branch will be processed, otherwise the else... branch will be
processed. The 'elif...' branch does what you would expect too.
Note that these cannot be nested, however. |
at | at location[,location...] | We are 'at' the listed locations. |
notat | notat location[,location...] | We are 'not at' the listed locations. |
always | always test... | Runs the test regardless of whether a previous test was successful. If we are within an inactive branch of an if ... elif ... else ... fi clause the test will not be processed, even when preceded by "always. |
testscript | testscript <parameter> <location list> | Anything else is assumed to be a script, which will
be run by the whereami process with the second parameter. If the script
exits with a 0 status, whereami will consider that the location(s) listed
in the third parameter are current. Note: that tests will only be run until one is successful, unless the test is preceded by "always". |
These commands should normally all appear on the same line. The HTML formatting here may break them into multiple lines for readability.
testdhcp | testdhcp [<interface>,](start|stop|restart|<IP address pattern>) location[,location...] | Gets a DHCP address (on the first call, or on the 'start' call) and compares it to the IP address pattern. |
testarp | testarp [<interface>,]<MAC address>,<IP address> location[,location...] | Look for that MAC address in association with that IP address on the specified interface. |
testmii | testmii <interface> location[,location...] | Check if there is a network present on the interface. |
testmodule | testmodule <pattern for lsmod> location[,location...] | Look for the pattern somewhere in the output of lsmod. |
testpci | testpci <pattern for lspci -v> location[,location...] | Look for the pattern somewhere in the output of "lspci -v" |
testping | testping [<interface>,]<IP to find>,<IP to use> location[,location...] | Configure the interface as the specified IP address and try and ping the other one. Note that this uses fping for speed, and makes assumptions about how long it is reasonable to wait for a ping response on a LAN. |
testpppoe | testpppoe <interface> location[,location...] | Attempts to establish a pppoe session. |
testreceived | testreceived <interface> location[,location...] | Check to see if we have received packets on that interface. |
testssid | testssid <SSID> location[,location...] | Look for a WLAN that is using that SSID. |
In my situation I have around 7 different locations I want to identify:
In most of these situations DHCP is set up, which makes things quite a bit easier because I can assume that the network adapter is already configured when whereami is run. At Catalyst I also use the lspci command to see if my computer is in its docking station.
For the home network I don't have DHCP set up yet, so I use testarp to look for a MAC address.
Since the docking station doesn't mean that I'm at Catalyst (in a 'network' sense), I do that check first, followed by checks for all of the DHCP addresses I might have assigned. Fortunately these all assign addresses on different class C ranges, so I don't have to get complicated and do 'nslookups' on assigned IP addresses and so forth, but the possible approaches are almost endless.
Someday I would like to add a script which gives some 'inertia' to the current location so that the last active location will weight my system's decision so that if I was last in Auckland it will assume that, since I am now off-line, I must be off-line in Auckland (so it could configure the defaults for ppp appropriately).
If the standard scripts (in /usr/share/whereami/...) are insufficient for your needs, you may want to develop custom scripts.
Each script to be used in detect.conf should:
If you want your script to allow for multiple parameters, you will need to use a comma-separated (or some other non-space character) list. You should look at some of the standard scripts for examples, if you don't feel confident in your scripting skills!.
Having found out where you are, what actions do you want your system to take?
Andrew's Linux Page | The 'Whereami' Utility | Location Detection | Whereami Actions | | © Andrew McMillan, 1999-2003 released under the GPL |