Ryan Harrison My blog, portfolio and technology related ramblings

Bash - Redirecting stdout and stderr

Redirect stdout/stderr to a truncated file:

# StdOut
cmd > out.txt # (stderr printed to console)
# StdErr
cmd 2> err.txt # (stdout printed to console)

Redirect stdout/stderr to a file (appending):

# StdOut
cmd >> out.txt # (stderr printed to console)
# StdErr
cmd 2>> err.txt # (stdout printed to console)

Redirect both stdout and stderr in same command to different files (truncating):

cmd > out.txt 2> err.txt

Redirect both stdout and stderr to same output (truncating):

cmd > out.txt 2>&1

“Redirection statements are evaluated, as always, from left to right. >> file - STDOUT to file (append mode) (short for 1>> file) 2>&1 - STDERR to ‘where stdout goes’ Note that the interpretation ‘redirect STDERR to STDOUT’ is wrong”


Read More

Htop Colours Explained

Htop is a great expansion to the top command in Unix based systems. Rather than just spitting out metrics to the console, htop provides a complete ncurses-based interface which makes it extremely useful when managing processes.

The header of htop contains a number of bars that show CPU usage, memory usage and swap usage. The bars are all colour coded to show different aspects of the usage. This is great when you know the what the colours mean, but htop doesn’t make it too obvious what they mean. The F1 (Help) menu offers a guide to the colours of the usage bars:

htop colour guide

Read More

Python - Simple HTTP Server

Python comes with a really handy built-in HTTP server that you can get up and running in a matter of seconds - and without having to mess around with something like Apache. This is great for serving simple web pages locally through HTTP to get around the limitations of the file:// protocol within the browser.

The command to start the server unsurprisingly differs from Python 2 to Python 3, but either way it’s really easy to remember. Simply open up a terminal, change directory to the folder containing the files you want to serve and either of the following to start the server depending on your Python version:

Python 2:

cd files/my-directory
python -m SimpleHTTPServer

Serving HTTP on port 8000 ...

Python 3:

cd files/my-directory
python -m http.server

Serving HTTP on port 8000 ...

Then navigate to http://localhost:8000 in your browser to see your files (by default you get a directory listing if there is no index.html file).

You can also specify the port you want to use if 8000 doesn’t work for you:

python -m SimpleHTTPServer 8080
python -m http.server 8080

Serving HTTP on port 8080 ...
Read More

Common Port Mappings

List of common ports and their uses/associated urls:

Port Application URL/Command
4000 Jekyll Serve http://localhost:4000/
9091 Transmission Web Client http://localhost:9091/
22 SSH (default) ssh ip.address
80 HTTP http://localhost
443 HTTPS https://localhost/
32400 Plex Media Server
8080 Tomcat Server http://localhost:8080/
3000 BrowserSync http://localhost:3000/
9200 ElasticSearch http://localhost:9200/
5000 Flask http://localhost:5000/
8000 Python HTTP Server python2 -m SimpleHTTPServer / python3 -m http.server
3306 MySQL Server  
25 SMTP (Postfix Mail Forwarding)  
587 SMTP (Postfix Outgoing Mail Server)  
Read More

New Dedicated Server with Kimsufi

In a previous post I talked about how I needed to move away from shared hosting to a server where I could get root access. Initially I looked at getting a VPS with Hostgator, but the prices seemed too steep for me with the specs they were offering. I then started to shop around, trying to find a VPS with a reasonable price to performance ratio. There are a ton of providers out there, some of course better than others. My first port of call was DigitalOcean who are a very popular provider of servers. For around £10 per month you can get 1GB of RAM and 1 processing core. They are very good if you want to spin up a server for a few hours, but as I intended on having mine up 24/7, I again thought I could do better price wise.

I then visited OVH who are known to provide extremely cheap VPS’s. At the time of writing, for around the same price you can get 2 vCores, 8GB of RAM and 40GB of SSD disk space. They certainly do live up to their reputation. They are known to not provide the best support on the market, but for that price I think that’s quite reasonable. Besides, I don’t really want to rely on support to fix my software issues - it’s definitely good experience to figure out Unix issues yourself (and I definitely have had to).

I was just about to order myself a VPS with OVH when I got linked to one of their partners - Kimsufi. They are a separate company yet their servers are located in OVH’s datacentres so you still get access to their extensive infrastructure. Kimsufi don’t really market their servers towards commercial needs, their website targets training, hosting and sandboxing - perfect! Kimsufi offer a set of 7 dedicated server models for crazy prices considering their specs (yes, that’s right they are dedicated not VPS’s). For around £12 you can get yourself a Core i5 and 16GB’s of RAM or for just £25 per month you can get yourself dual Xeon processors and 24GB’s of RAM - crazy right? The low price does of course come with it’s drawbacks. Kimsufi will tell you themselves that they offer barebones support. If you have a software problem, then expect to have to fix it yourself. Of course they will still fix your server’s hardware if it fails at any point. I settled on the KS-3 model which gives you your very own dedicated server with:

  • Intel Core i5-3570s @ 3.10GHz (4 cores)
  • 16GB RAM
  • 2TB Disk Space
  • 100 Mbps network link (unmetered)
  • 1 dedicated IPv4 and Ipv6 address

It was a little more than I wanted to pay, but who doesn’t want their own dedicated quad core server? With these specs I was also able to set up a lot more software than I initially intended and I never have to worry about the performance implications. Although I wanted to get hold of a Kimsufi server, it wasn’t that easy however, if you look at their website you will most likely see that all of the models are currently being replenished. They do become available every so often, but they sell out again almost immediately. Handily, there are a couple of websites which will alert you when a particular model becomes available so you can pounce as fast as possible:

Whenever you get an alert email make sure you take action straight away. It takes some effort to get hold of one these servers. Also expect the ordering process to fail right at the end when they sell out whilst you are ordering (they don’t reserve you one during checkout). It took a while, but eventually I got hold of a KS-3 and I’ve been very happy with it so far (~6 months). In the end my processor was even better than the one they advertise and otherwise you get exactly what you pay for. The control panel is simple but functional (I’ve never really needed use it apart from when installing an initial Linux distribution) and the network speeds are great. I’ve had a lot of fun and learnt a load setting up and configuring a Linux server (I will post more about this in the future). If you are looking to do the same and want to get your hands on a dedicated server, then I would definitely recommend you check out Kimsufi.

Read More