A poor man’s dynamic DNS on a Raspberry Pi

If you want to connect to your Digital Video Recorder (DVR) or ownCloud installation from the internet, you need to know to which IP address you need to connect (See this DVR article as well). The bad thing however is that the most of us don’t have a fixed IP address on the internet (this might change in the future with IPv6). This means your IP address can change in time. There are several payed services to solve this problem like DynDNS, DuckDNS, DtDNS, No-IP, etc. Most of the time you are the only user of the services you are hosting at home, if so than there is a cheap solution.

As described above the whole thing is, that you need to know which IP address your Raspberry Pi has. The solution is to write a script that checks your external IP address and that sends you an email in case the external IP address has changed.

Login on your Raspberry Pi with SSH:

ssh pi@your IP address
cd ~
nano ./ipaddrcheck.sh

 

Now copy and paste the following code to nano (of course you need to change username@domain.ext to your own email address):

#!/bin/bash
curl -o ~/newip ifconfig.co
cmp ~/newip ~/oldip >/dev/null || {
mv ~/newip ~/oldip
mailx -s “I – IP ${HOSTNAME} changed” username@domain.ext < ~/oldip
}

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

Make let’s make the script executable:

sudo chmod +x ./ipaddrcheck.sh

 

Let me roughly explain what the script does:
It’s a bash script that checks the external IP address by using curl ifconfig.co and writes the results to a file called newip.
After that it checks whether the IP address has changed by comparing the files newip and oldip, in case the two files are not the same it sends you an email.

 

Now we need to install the necessary packages to sent mail:

sudo apt-get install ssmtp heirloom-mailx

 

The next thing is to configure your Raspberry Pi so it’s able to send mail. Therefore you need to add the following lines, at the end of the file /etc/nail.rc :

sudo nano /etc/nail.rc

 

Now copy and paste the following code to nano (of course you need to change: smtp.domain.ext, username@domain.ext, password and email sender’s nice name to your own email settings):

# Smtp server
set smtp-use-starttls
set ssl-verify=ignore
set smtp=smtp://smtp.domain.ext
set smtp-auth=login
set smtp-auth-user=” username@domain.ext
set smtp-auth-password=”password”
set from=”email sender’s nice name”

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

Now we need schedule and execute the script by using crontab:

crontab -e

 

Add the following line, at the end of the file (it schedules the ipaddrcheck.sh every hour):

0 * * * * /home/pi/ipaddrcheck.sh

Use Ctrl O to save the file
Use Ctrl X to exit the nano editor

 

You can check the date and time stamp of the file ~/newip to see whether your script ran.

Changing the IP address in ~/oldip enables you to check whether emailing works, as it should send you an email the next time the sript runs.

 

PS. if mailing yourself doesn’t work, try editing the /etc/ssmtp/ssmtp.conf file (as it heavily depends on your mailserver configuration).

 

Suggestions for improving this article are welcome, please let me know and drop me a line .

How to erase (or clean) a disk using Ubuntu

Sometimes you just want to clean a USB stick, SD Card or USB disk, and the only thing you’ve got is Ubuntu running on your system.

Well that is no problem, I’ll explain how simple it is…

Cleaning, erasing, wiping a USB stick, SD Card or USB disk can be done in just 3 simple steps:

  • Connect your disk
  • Identify the disk on your system
  • Clean / wipe your disk

Step 1 – Connect your disk
Connect your USB stick, SD Card or USB disk to your computer and mount your disk (you can do that by double clicking its icon on your desktop).

 

Step 2 – Identify the disk on your system
Open a terminal:

df -h

or, you can use

sudo fdisk -l

Identify your disk (you can look at it’s size or partition scheme)

 

Step 3 – Clean / wipe your disk
The following command is a simple example to understand the use of dd. Do not simply copy it and use it in a terminal !!! Remember the order of the options “input file (if=)“ and “output file (of=)” , DO NOT reverse them !!!

In my case (the example below), I identified my disk that I wanted to clean as /dev/sdg.
So my output file (or of) will be /dev/sdg this will result in of=/dev/sdg

Open a terminal:

sudo dd if=/dev/zero of=/dev/sdg

 

When the dd command is issued and ready, make sure all data is written to disk by typing the folowing in your terminal:

sync

 

Suggestions for improving this article are welcome, please let me know and drop me a line .

How to install SoftSqueeze on Ubuntu

Softsqueeze is a software music player developed in Java (allowing it to work on most operating systems) that works with the Squeezebox Server software. Softsqueeze emulates most of the Boom, Duet, Transporter, Squeezebox and Slimp3 hardware music players. It uses a TCP based protocol, allowing it to use across the Internet and through firewalls/NAT routers using ssh tunneling. The software music player supports synchronization with hardware players.

Prerequisites (what you need to get it working):

  • Hardware
    • Computer running Ubuntu
    • SqueezeCenter Server
    • Network connection
  • Software
    • SoftSqueeze

 

Let’s get started:

Download the java version of SoftSqueeze (the .zip file) from your favourite browser.

Create a folder called SoftSqueeze in your home folder by opening a terminal window (Applications \ Accessories \ Terminal).

mkdir SoftSqueeze
cd SoftSqueeze

 

Now unzip the zip file:

unzip ~/Downloads/softsqueeze_3.8.zip

 

Make the JAR file executable:

sudo chmod +x SoftSqueeze.jar

 

Install Sun Java 6 Runtime:

sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-fonts

 

Make JAR file open with Java:

java -jar ~/SoftSqueeze/SoftSqueeze.jar

 

The only thing left to do in Softsqueeze is to point it to the SqueezeCenter Server and redirect the audio output to “Java Sound Audio Engine”.

 

Suggestions for improving this article are welcome, please let me know and drop me a line.

Ubuntu upgrade resulting in a no sound situation

After working happily a couple of months with Ubuntu 10.04 I installed a new kernel with the update feature. This resulted in not having any sound or volume controls. After reading a lot on internet articles  I found the following article… Comprehensive Sound Problem Solutions Guide v0.5e I followed the following commands that brought back sound to my notebook.

Getting the ALSA drivers from a *fresh* kernel

Sometimes, sound might be configured correctly, but for some reason or another (tinkering) it stops working. One way to go back to the old setup is to reinstall Ubuntu. However, this step is actually quite unnecessary since you are reinstalling everything because of one thing.

A faster way, is to just remove the problematic packages and reinstall them cleanly.

Step – 1: Remove these packages

Code:

sudo apt-get –purge remove linux-sound-base alsa-base alsa-utils

Step – 2: Reinstall those same packages

Code:

sudo apt-get install linux-sound-base alsa-base alsa-utils

[LIST][*]

VERY IMPORTANT NOTE: Ubuntu (GNOME) users have reported that packages ‘gdm’ and ‘ubuntu-desktop’ are removed after removing the linux-sound-base packages. If this happens, then do the following

Code:

sudo apt-get install gdm ubuntu-desktop

Step – 3: Reboot

Using Excel’s conditional formatting to colorize the weekends

In this period of the year most of us are starting to make plans for next year, Excel is an incedibly powerfull tool that can help you visualize your plans. Using Excel’s conditional formatting you can colorize the weekends and make them standout more than the other days of the week or vice versa. This article is an How to colorize the weekends in Excel using conditional formatting.

To colorize the weekends in Excel using conditional formatting, based upon the date in column B, you can use the following formula:

=IF(OR(WEEKDAY($B2)=1;WEEKDAY($B2)=7);1;0)

 

To create a rule using conditional formatting:

  • Select the cells that you want to apply the conditional formatting to.
  • Click “Conditional Formatting”.
  • Choose “New Rule”.
  • In the “New Formatting Rule” dialog box, choose “Use a formula”.
  • Under “Format values”, type the formula: =IF(OR(WEEKDAY($B2)=1;WEEKDAY($B2)=7);1;0)
  • The formula uses the dates in column B (You can select your own column with dates, by replacing the $B2 part in the formula with the column letter of your choice).
  • Click “Format”.
  • In the “Color” box, select your favourite color.
  • Click “OK” until all dialog boxes are closed.

 

Suggestions for improving this article are welcome, please let me know and drop me a line.