Finding Your Phone, the Linux Way

If you have a Nokia N900, you can set it up so that it helps you find it the next time you lose it. The methods shown here, with modifications, can be used on other Linux phones as well.

Listing 1. lost.sh

#!/bin/sh
# A script to help you find your phone.
# by Daniel Bartholomew, May 2010
#
# This script is licensed under the terms of the
# GNU General Public License, version 3 or later.
# See <http://www.gnu.org/licenses/> for details.
# Some variables you need to set:
amilost="http://example.net/my-n900-is-lost.txt" # CHANGE THIS!
username="username" # the username at your ssh host
sshhost="hostname"
backupnumber="3215551212" # backup phone that can receive SMS messages
# A timestamp variable you can alter if you want to:
timestamp=$(/bin/date +%Y-%m-%d-%H.%M.%S-%Z)
# With the vars out of the way, we can begin:
# The first step is to check for the file on the webserver.
# If it exists, we collect data and send it,
# if not, we print a message and exit.
if wget --output-document=/tmp/${timestamp}.txt \
${amilost} 2>/dev/null; then
# If we're here, the file exists and the phone is lost.
# Get the current IP address and send it using the
# sendsms.py script:
/sbin/ifconfig -a \
| awk '/inet addr/ { print $2 }' \
| awk -F: '{ print $2 }' \
> /tmp/${timestamp}.ip
# sendsms.py from:
# http://talk.maemo.org/showpost.php?p=558430&postcount=57
/home/user/sendsms.py ${backupnumber} \
"$(/bin/cat /tmp/${timestamp}.ip)"
# take a picture with the front-facing camera
/usr/bin/gst-launch v4l2src \
device=/dev/video1 \
num-buffers=1 ! \
ffmpegcolorspace ! \
jpegenc ! \
filesink location=/tmp/${timestamp}.jpg
# get the location and send it
# gps.py from: http://talk.maemo.org/showthread.php?t=47301
/usr/bin/python2.5 /home/user/gps.py 2>&1 > /tmp/${timestamp}.gps
/home/user/sendsms.py ${backupnumber} \
"$(/bin/cat /tmp/${timestamp}.gps)"
# More things can be done.
# See http://wiki.maemo.org/Phone_control for
# ideas. Experiment and have fun!
# (But don't blame me if you accidentally brick your phone.)
# We've gathered the data we want, now copy everything to the sshhost
# server
# (need to have ssh-keys set up for this to work).
/usr/bin/scp -i /home/user/.ssh/id_rsa /tmp/${timestamp}.* \
${username}@${sshhost}:
# What if I want to run more commands than are listed above,
# such as making the phone vibrate or having it call me?
# The file I downloaded from the server can contain special
# commands. If the file is empty, nothing will happen.
# This probably is not the most secure thing to do, but if the
# phone really has been stolen, this will allow you to pull
# data off of it and/or brick the phone on purpose. Be careful!
# Only uncomment the following line if you know what you are doing
# and are comfortable with the consequences. I am not responsible
# if you break your phone.
#/bin/sh /tmp/${timestamp}.txt
else
# if the file on the server doesn't exist the phone is not lost:
echo "I am not lost."
fi
# That's it! We're done.
exit 0

I decided it would make the most sense to watch for three different
actions:

The phone changing networks.

The keyboard being opened or closed.

Low power.

If the network changes, that probably means the phone is on the
move (maybe I left it in a car). If the keyboard is opened or closed,
someone is using or looking at the phone. Finally, if the phone
is just sitting there, eventually the batteries will drain away (and
I'd like to find the phone before all power is gone).

The three lines in dbus-scripts-settings that watch for those actions are the
following:

The lost.sh script is called each time one of those events occurs. The
dbus-scripts Wiki page (wiki.maemo.org/DbusScripts) has more
information on formatting the configuration lines.

See the lost.sh script (Listing 1) for details of what it does. One thing I found
in testing is that some of the commands I can run on the command
line do not work at all when called from a script by the dbus-scripts
dæmon. These include the mplayer command and setting the phone to
nonsilent mode. Thankfully, other commands work fine when called from
the script.

With the SMS script in place and called by the lost.sh script, all I
have to do is create the special file on my Web server, and suddenly my
N900 starts sending my designated backup phone (my wife's cell phone)
SMS messages whenever one of the events I configured happens.

Trending Topics

Upcoming Webinar

Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report

August 27, 2015
12:00 PM CDT

DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.