Before you can use your computer as a bluetooth proximity detector, first make sure your dongle works.
hcitool scan
can show discoverable devices easily enough,
but that's technically a security hole. Making your device not
discoverable increases your security slightly, and is recommended.
If your device is not Discoverable, how can you detect Bluetooth devices? 'hcitool cc $MACID' is not good, because it actually causes the device to wake up, and usually beep. That can be annoying. 'hcitool name $MACID' is perfect - it tells you whether a device is present without causing anything visible to happen on the device.
So it seems easy enough, just run while true ; do hcitool name
$MACID ; done
, right? Not quite, as there are a few things to
worry about. First, you don't want to drain the battery on your phone
dead by asking it to continuously talk to you saying "yes, I'm here".
Second, hcitool maintains a cache and only refreshes it if it's more
than X seconds old. So you should sleep for a period of time between
running the next 'hcitool name $MACID'.
I wrote a script that called hcitool name on half a dozen devices (laptops, headsets, phones) once every 30 seconds, but after a few days, hcitool started telling me '?' and stopped working altogether. I unplugged and re-inserted the bluetooth dongle, but that only worked for another day or two before re-plugging the bluetooth dongle didn't help at all. I'm not sure whether this is because of the inferior nature of my dongle or whether I'm tripping across some sort of bug in the bluetooth stack. Since I can't rmmod the kernel module, I'm leaning towards either a driver or dongle issue.
So I have a tool that works, but eventually ends up with a unusable bluetooth device. I have considered making the sleep timeout very long like an hour, but the uptime on my house server typically runs 2-300 days between reboots. With that sort of uptime, I'm always going to end up with a dead bluetooth dongle.
The hcitool name cache is /var/lib/bluetooth/$DONGLE_ID/names
.