Jamie's Notes

Currently browsing technology ⤵

Easy public SAMBA shares

I use Samba to share files with my Linux based media servers. It’s a pain in the arse and I hate it. Getting a share on the network is easy but the permissions punch me in the face. I’ll often end up with a share writable by one user but not another, or writable by many users but the files only readable by other users. Last week the whole wobbly system broke down because of a permissions issue and I was forced to figure it out once and for all. Turns out that I was over thinking it, and that it’s actually quote simple. Assuming that Samba is already installed, here’s a simple method for creating a public Samba share:

Step 1: Create the share location

sudo mkdir -p /share/media    
sudo chown root:users /share/media
sudo chmod 2775 /share/media 

Step 2: Add your local user to the ‘users’ group.

sudo adduser <username> users

Step 3: Configure SAMBA

Add the following to the bottom of /etc/samba/smb.conf

comment = Shared Data    
path = /share/media    
browseable = yes    
guest ok = yes    
force group = users    
writeable = yes    
create mask = 0664    
force directory mode = 0775  

Finally, restart Samba to initialise the new configuration.
sudo service smbd restart

You might need to log out and back in again for the permission changes in step 1 to take effect.

Analysing Pager Traffic with a Cheap USB Radio

I’ve been having some fun with a cheap USB FM/Dab radio. With some clever software this little gadget can do a lot more than it was designed to do, including decoding pager messages. People really do still use pagers.. The pager as we know it was invented in 1956 by Multitone Electronics for use in London hospitals, but it was Motorola who gave the device a name and introduced it to the masses. The popularity of the pager surged in the 1980s as it became the must have gadget of professionals. Teenagers and pop stars jumped on board in the nineties and it looked like the pager was here to stay, but as pager use grew so did the mobile phone network which eventually supplanted it. Mobile phones became more reliable, affordable and feature rich and usage of pagers dived.

Pagers still have some advantages over mobile phones. Coverage tends to be better, especially indoors and their battery life can be measured in weeks rather than hours. They can be used in places where mobile phones are banned for security reasons, or where they might interfere with sensitive equipment. Pager messages are broadcast in clear text by powerful transmitters over FM radio bands. You’ll need a cheap USB DAB/FM radio receiver to decode them. I bought mine for less than a tenner.

A search for ‘sdrsharp pager messages’ should give you give you all of the info needed to get up and running. For the technically inclined, the system works by modulating a tone between two frequencies to create a binary stream. The transmitter alternates these frequencies very quickly – up to 6400 times a second. Here’s a sample of some of the messages that I decoded:

0101158 23:39:12 29-07-15 FLEX-A  ALPHA  3200  FROM GLOUCESTER POLICE CONTROL ROOM, 

0121305 23:01:17 29-07-15 FLEX-A  ALPHA  3200  PLS CALL ANNE AT OBSTETRIC THEATRE 
ON 458 47`` 

0118459 23:58:43 29-07-15 FLEX-A  ALPHA  3200  20150729 23:57 boc1web03.servstream.

0119043 23:58:45 29-07-15 FLEX-A  ALPHA  3200  Room S17 Isolator Z21 Hatch Pressure 
BMT  42.5 (Alm:D Lmt:<50.0000 Grp:BMT)

I’m surprised that no effort is made to encrypt the messages because many of the messages contained personal details such as names, addresses and phone numbers.

Warning: It is extremely unlikely that this will get you in trouble, but decoding pager messages is illegal. See Section 48 of the UK Wireless Telegraphy Act for more information.

Using SSH Keys and Putty to Access Remote Servers

This tutorial assumes that you have a basic level of knowledge of Linux commands and can access a remote system using SSH. You will need PuTTY & PuTTYgen.

Direct links to portable versions of both applications are above, but you can also download a windows installer that has everything that you need from here.

Using PuTTYgen to generate a key pair

Open PuTTYgen and create a new key pair. The on-screen prompts are self explanatory and the defaults will work just fine.

Save a copy of each of the keys. It’s probably wise to password protect your private key so that it can’t be stolen. Keep both keys somewhere safe.

Select all the text in box labeled ‘Public key for pasting into OpenSSH authorized_keys file’ and copy it to the clipboard. The sequence should start with "ssh-rsa".

Preparing your SSH server.

Login to your SSH server. Navigate into your .ssh folder and paste the SSH key into the authorized_keys file. If it isn’t there, create it:

mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys

You can logout from your server for now.

Preparing PuTTY to login with your private key file.

Fire up PuTTY and enter the host name and port for your SSH server. In the navigation tree on the left, click ‘Data’ and enter the user name that you use to login to your SSH server.

Now click on ‘SSH’ and then ‘Auth’. Click browse and locate the private key file that you generated with PuTTYgen.

Scroll to the top of the navigation tree and click on ‘Session’. In the ‘Saved Sessions’ box, give your session and name and hit Save.

That’s it. Your SSH server and PuTTY are now ready to connect without passwords.

Owncloud & Missing Data

I’ve been using ownCloud for a couple of months. Mostly it works really well but there are times when it isn’t quite as slick as its commercial counterparts.

One of the most disconcerting things that has happened so far was discovering that tens of gigabytes of files had disappeared from my computer. The sync client log said that they had been deleted, which was odd because I definitely didn’t do it. I checked the web interface, hoping that it was a local error, but they were gone from there too. I fired up a terminal, ssh’d into the server and checked my data directory manually. Thankfully of my files were there – but they were in some sort of limbo, not accessible to either the web interface or my local sync client.

Frantic googling showed that I am not the only person that this has happened to. There are a couple of ways to fix it, but the simplest solutions is to force ownCloud to perform a complete scan of your data directory and make the missing files available again. The following command will do just that:

sudo -u www-data php /var/www/owncloud/console.php files:scan --all

You might need to do it a couple of times. The initial scan brought the files back into the web interface, but I had to do it again before they would sync to my laptop.

Six Months with the Fitbit Flex

I have been wearing a Fitbit Flex since June 2013; a little over six months at today’s date. This neat little gadget sits on my wrist twenty four hours a day, seven days a week and silently monitors my activity levels. It’s basically a clever pedometer, but it also tracks sleep.

Now that I have gathered plenty of data, I thought it would be useful to see what it can tell me about my lifestyle.

How I Got the Data

Fitbit offers a comprehensive dashboard to view your data at no additional cost. It’s pretty good for day to day use – but you are restricted to viewing your data in the way that their interface prescribes.

Fitbit also offers an API for application developers, from which they can pull data. I’m not nearly clever enough to do anything with it, but the very clever Mark Leavitt has created a script for Google Sheets called ‘Fitbit Download’ which sucks down all of your data through the API and places it in a spreadsheet. You can download it through the Script Gallery. There are a couple of extra hoops to jump through before you can get at your data, so take a look at the full instructions.

So, what does all this data tell me?

General Activity Levels

The data is quite depressing reading. My activity levels are very low. I am officially, by most definitions, sedentary. I’m an Outreach Worker by trade. The job title suggests that I am pounding the pavements on a regular basis. That is not the case. The majority of my work hours are spent in client’s homes, in the car, or writing up reports. 

Fitbit sets you a goal of ten thousand steps a day (roughly five miles) but I quickly realised that I was never going to meet that, so I lowered it to seven and half thousand. Even that lower figure turned out to be optimistic. My average daily step count over the whole dataset is just 5879.

Broken down by month (not including partial months):

  • July: 6759
  • August: 6124
  • September: 6462
  • October: 5391
  • November: 5044
  • December: 5257

My activity levels are showing a downward trend. Perhaps due to the change in seasons? I should probably do something about that.


I like sleep – but I often feel that I don’t get enough. Everyone needs different amounts of sleep to be able to manage effectively the next day. I reckon that I need seven hours to feel fully rested.

Fitbit collects a few different data points for sleep. It calculates the time difference between getting in bed and waking up in the morning, and subtracts any time that I’m restless. The data shown above is pure, deep sleep.

My average over the period is 424 minutes, or 7.06 hours. That’s pretty good! However, the data shows that my sleep pattern is unpredictable. I’ll get five hours some nights and nine another. I don’t think that my body can work out what is going on.

For no reason that I can fathom, Thursday is the day that I get the least sleep – and Sunday the most. Here are my daily averages:

  • Monday: 7.11
  • Tuesday: 6.86
  • Wednesday: 6.91
  • Thursday: 6.53
  • Friday: 7.05
  • Saturday: 7.42
  • Sunday: 7.63

What the heck is going wrong on Thursdays?!

Is it useful?

This is only a small subset of the information that can be pulled out of the Flex. I use it as a motivator more than anything – a constant jab in the ribs to remind me that I need to do more. Often that does not translate into direct action, and that’s the bit that I need to work on if I am going to make some of this data more positive. Fitbit provides the carrot by giving me useful data – now I’ve got to use the stick to get me out there.

Scanning for Bookmooch using Android

I’m loving my new Android phone. It’s a real smart piece of technology and I keep finding great applications for it. One neat application that I have found is the Android Scripting Environment , which basically does what it says on the tin, allowing you to create quick and dirty scripts, on the device, which make use of the extensive Android API.

One of the example programs that came with the application made use of the barcode scanner to add a book to Google Books. I’ve adapted this program to allow you to quickly add a book to your Bookmooch inventory, just by scanning the barcode on the back of a book.

It’s a bit rough and ready but a fun little hack.

Here’s the code:

import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code['result']['SCAN_RESULT'])
url = ("http://bookmooch.com/m/add_do?text=%d" %isbn+"&store=amazon.co.uk")

The original code, along with a load of other examples can be found here . I’d love it if someone were able to develop this a bit more, if only to provide a nice exit routine. Sadly that’s way beyond my ability.