Raspberry Pi phone home with IP address

Sometimes it’s a pain to keep track of your Raspberry Pi’s IP address. Maybe you want to plug it in on a work or friend’s network without having to plug in a keyboard and mouse. This technique is what I am using to know the IP address of my Raspberry Pi’s no matter how often they change or what the IP address is.

This requires that you have a web server. I’m logging the IP addresses into the web server log files, Apache in my case.

The script source code is here:


ETH0=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
WLAN0=`/sbin/ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
if [ -n "$ETH0" ]; then
curl ${SERVER}/locater/${HOST}/eth0/${ETH0}
if [ -n "$WLAN0" ]; then
curl ${SERVER}/locater/${HOST}/wlan0/${WLAN0}

Make sure to set “http://example.com” to a web server name that you own!

I set up a crontab to run this script every 5 minutes:


*/5 * * * * pi /home/pi/bin/send-ip-addr.sh

This will drop an entry into your server log files every 5 minutes that looks like this:

[01/Dec/2015:22:25:01 -0500] "GET /locater/pi2b/eth0/ HTTP/1.1" 200 183 "-" "curl/7.26.0"

The useful bit is the location that is requested /locater/pi2b/eth0/
Split the slashes and you get /locater/ then the Raspberry Pi hostname, interface (eth0 or wlan0), and IP address.

I use this technique to keep tabs on the current IP address of nine of my Raspberry Pi computers so I can access them regardless of what IP address they get, or where I plug them in. This also lets me know how many of them are online at any given time since they will phone home every 5 minutes together.

To see the logs, hop on your web server and tail your log file, filtering out the word “locater”. Your log file path may be different, so change /var/log/apache2/access.log to your log file name:

tail -f /var/log/apache2/access.log | grep "locater"

If you want to make the log entry show up as a “HTTP 200 OK” instead of a “HTTP 404 Page Not Found” you need to put a hack on to your web server. This is useful if you run statistics and you do not want a bunch of ugly 404s to show up.

I’m running Apache so I created this directive which will catch any URL request under /locater (since the script fakes subdirectories):

Alias /locater /opt/locater.htm

…with a file at /opt/locater.htm

It doesn’t matter what is in the file, as long as it exists.

Create a bootable OS X El Capitan installer

This is how to create a OS X El Capitan installer on a flash disk or external disk.

Download OS X El Capitan from the App Store. When it finishes downloading, quit the installer. The “Install OS X El Capitan” application should be in your /Applications folder. On a side note even if you do not create a bootable installer, it’s a good idea to get a backup of this installer before running it. After upgrading your system, the installer will remove itself.

Format a flash stick Mac OS Extended (Journaled) with GUID Partition Table

Name the disk “Untitled”. Simply because the command below references the disk by the “Untitled” name.

In Terminal, run:

sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia –volume /Volumes/Untitled –applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app –nointeraction

tcpdump ASCII

tcpdump out ASCII characters and not see headers

-s Snap Length – Grab the entire 1500 byte packet
-l stdout line
-i interface

tcpdump -s 1500 -A -l -i eth0

How to stop Amazon Music Helper from running in the background OSX

After installing Amazon Music on my mac, I noticed this background task “Amazon Music Helper” running. I tried to kill it, it came back.

The fix I used was to remove execute permission on that file:

chmod -x /Applications/Amazon\ Music.app/Contents/MacOS/Amazon\ Music\ Helper

Then kill the process again and it shouldn’t come back.

I have bought music since then and find that all the features (that I use) work fine. This thing isn’t even needed!

Start a screen session as another user at system startup

Came across this technique to get a screen session started as another non-root user on system startup. You could have this command in /etc/rc.local or any other location that runs on system startup as root.

Also, it doesn’t have to just be at system startup. These commands could be used at any time by the root user to start a screen session for another user.

This command must run as root. I had best luck when providing full paths to the executable and optional file arguments (like if you are passing a conf file)

su - username -c "/usr/bin/screen -dmS screenname ./executable"

So, for example, to get irssi started as chris in a screen session named irc, You could:

su - chris -c "/usr/bin/screen -dmS irc /usr/bin/irssi"

You can then log in to the box as chris and resume the screen session that root started.