Parsing JSON in Bash is never usually the best idea but sometimes it may be necessary or preferred. Here’s a nice easy script which uses the ‘jq’ command to perform JSON parsing in Bash.
Let’s imagine you have the following JSON which is outputted by a stats gathering process:
Parsing that in Bash by writing some regex’s etc is perfecting possible but there’s an infinitely easier way. Welcome to ‘jq’. Let’s see it in action.
Even having written many hundreds of Bash scripts over the years I sometimes forget the basic special parameters which are available. For that reason I’ve made this post which is a copy of the page from gnu.org.
If you have an APC UPS you may not, for whatever reason, want the OS to trigger a shutdown. The ‘apcupsd’ package will call shutdown whenever the battery capacity is reported too low. To prevent this, just edit the following file.
Here is a very simple way to download iPlayer content using a Linux command line tool. This literally downloads the stream and saves it to a file. The best part is, because they’re not DRM protected, you can keep it forever.
Very quick post on how to resize a VirtualBox virtual disk.
When using QCOW based disks with Virtual Box there’s no automagic method for resizing the disks. Because of that you first have to convert it. Here’s the commands you need…
I thought a wee article on what a server is and why they are expensive compared to your average PC might be interesting. When you hear someone say they have built a server for the house what they usually mean to say is they’ve built a PC and have it running various applications which serves ‘stuff’. A real server is a different beast all together.
So what makes a server a server? It boils down to the hardware feature set. Sure, you can get low-end servers which are nothing more than a PC in a fancy rack mount chassis, but lets take a look at higher end goodness.
This will be a quick tutorial on how to configure an Exit Node for the Tor Network. Doing this comes with some inherent risks for the operator but exit nodes are essential for bridging Tor with the ‘clear net’. Without exit nodes, anyone suffering from ISP filtering or those not wishing to have their Internet activity logged (BBC Article) couldn’t utilise Tor to access the Internet.
Unlike bridges, exit nodes (and normal relays) are publicly known devices, for which their IP address and configuration is available for anyone to see. They effectively make the final connection to the destination on behalf of the originating (anonymous) client. The Tor network is drastically short of exit nodes, but for good reason. Because they are the final hop in the chain, they will be making hundreds of outbound connections to whatever website or service Tor users request. It is therefore easy for the powers who be to blame an exit node operator for ‘doing bad things’ when in fact their node is merely participating in a network, much like a traditional router would in any network. Anyway, assuming you have balls of steel and willing to run an exit node I’ll take a look at how to do this with least hassle as possible.
Tor (‘The Onion Router’) is by far the most popular solution for anonymous browsing, with over 6000 relays and 2.5 million active users. I’m going to look at how to configure Tor on your network, in a variety of ways. The so called ‘Dark Web’ seems to get a bad press, maybe because of illegal sites like Silkroad, but it’s actually an invaluable resource for citizens or visitors to countries who have severe Internet censorship (including the UK!). Even Facebook has a .onion address, as does the DuckDuckGo search engine and Aphex Twin’s ‘Syro’ album.
By far the simplest and most secure way of using Tor is to install the Tor Browser. It’s dead simple and takes literally a few minutes. However, depending on your goal, there are other ways to use Tor. I’m going to look at a few ways to deploy Tor, including the pros and cons of each. These are:
- Using the Tor Browser Bundle
- Configuring a Tor SOCKS proxy
- Creating a transparent Tor network
FreePBX is an opensource front-end for the Asterisk VoIP solution. It can be installed on a Raspberry Pi via a prebuilt image but what if you want to use it directly on Raspbian (or other distros)? Well, it is possible with a few minor tweaks.
Because FreePBX and Asterisk are tightly bound it is a permissions nightmare to get the web interface to work with any other user than ‘asterisk’. If you already have Apache running for other purposes then this is obviously not ideal. For this reason we need to get second Apache process running as the ‘asterisk’ user, while at the same time allowing the main Apache process to run as is. Here’s how you do that.
There are many tutorials on rebuilding Linux Software RAID but most are unnecessarily overly complicated. It’s fairly straight forward – here’s how.
Unlike hardware RAID, software RAID is all handled by the operating system itself. This means the process of replication, rebuilding and control is performed by the filesystem with various kernel and userspace software.
If, like me, you use a Raspberry Pi as a multimedia centre it’s really handy being able to kick off a torrent without having to be logged into the Pi. This is especially useful if you want to download something using your phone, to your Pi, from literally anywhere.
Here’s how to configure Transmission so you can download torrents to your Pi from anywhere.
After posting how great Tarsnap is I thought it only fair to write a ‘how to install Tarnsap on Linux’ article, so here goes.
Sign up for an account
This is the easiest part, simply create an account at Tarsnap.com and verify your e-mail address. You will need to ‘top up’ your account with at least 5 American Pasos to actually get started so may as well do that right away. I used Paypal as it makes me feel safe and when I feel safe I sleep better at night.
Once you have an account balance there’s actually not much else to do via the website; the rest is all command line goodness.
Download and Compile the Source Code
I’m going to do the rest as the ‘root’ user. If you’re not feeling as brave you may wish to prefix every command with ‘sudo’ as your normal user – for some reason Ubuntu et al seem to love doing this.
At the time of writing version 184.108.40.206 was the latest.
First up lets get root and change to /tmp and then download the tarball:
sudo -i cd /tmp/ wget https://www.tarsnap.com/download/tarsnap-autoconf-220.127.116.11.tgz
Tarsnap is a no nonsense backup service for Unix (Linux, Mac etc) and is very nice indeed from a sysadmin’s point of view. It is inherently uber secure by design. It somewhat lacks being end-user friendly though – for example it doesn’t handle expiry of archives out-the-box. Therefore if you wanted GFS style rotation you need to wrap it in something which handles deleting old archives according to whatever deltas.
Their payment model is a bit strange in that it is prepay so you get a warning email when running low on credit or risk having your backups deleted for good. The cost of a particular backup run can more »
I’ll be writing a post about how great Mopify is shortly but essentially it’s a web plugin for Mopidy which provides a web front end to Spotify running on just about any machine. It means you can control Spotify running on a machine plugged into your HiFi without the needs for the Spotify App on your device. This is handy where you have other people in the house with their own accounts but still want them to be able to control the music on the main HiFi.
Of course, an ideal host machine might well be a Raspberry Pi with a decent USB Soundcard.
Mopidy runs its own little web server which means more »
I wanted a way to detect if someone was in the house without anyone having to do anything. This is useful, for example, to run a script or launch a program if we can identify who it is. The solution I wanted to play with was using mobile phones. Given that folks are fairly attached to their phones these days this seemed a reasonable detection method.
The script below is written in Python and uses bluetooth to detect if anyone more »