Bash: Random numbers for fun and profit

bash has many things that just works automagically. Did you know it has a built-in pseudo-random number generator? Let’s play games!

Before continuing, note that this is pseudo-randomization with a small footprint. DO NOT use it for security, scrambling, passwords, or anything even scarcely security related.

Matching a message
Image by XKCD, CC-2.5

The random function in bash is called by the magic variable RANDOM. It gives you a more or ... [continue reading]

Serving a static website from bucket storage

As mentioned in a previous blog entry, this site is deployed to an S3 website bucket when the Git master branch receives a push. I will here explain how we created and configured the website bucket in question, as well as explain the varnish configuration in front of it.

The S3 storage we use is Ceph with a S3-compatible Ceph Object Gateway (radosgw) interface, but the process should work for any S3 compatible storage with website-bucket functionality.

In this ... [continue reading]

Read logs in PowerShell console

Read logs in PowerShell console.

It’s easy to get lost in Windows large event logs and log files during troubleshooting, here to help are PowerShell cmdlets Get-EventLog and Get-Content.

These cmdlets shows PowerShell’s strength comparing to the built-in GUI-tools in Windows. Let’s start with cmdlet Get-EventLog to get some information from an event log. Examples below is how I often work with these cmdlets when searching for logged events on hosts.

Start PowerShell from a command prompt by typing ... [continue reading]

ncat, a modern implementation of Netcat

ncat is a utility that is like the UNIX cat command but for network connections. It’s based on the original netcat and comes with a couple of more modern features.

In this short post, we’ll go through a couple of examples to see exactly what uses this tool has. I’m currently using ncat version 7.01, in Ubuntu 16.04. ncat is a part of the nmap package in Ubuntu.

Shiny new things

A couple of the features of ncat, some ... [continue reading]

Slimming down the Internet routing table

When an ISP or Autonomous System (AS) such as Redpill Linpro acquires a block of globally unique IP addresses (called a prefix), it must advertise it to the global Internet routing table. This advertisement causes all other ASes in the world to find out that the new prefix is now alive, and also how and where to send any IP packets destined for it. Connectivity is established, and everybody is happy. Right?

Except there is a problem. The ... [continue reading]

Elastic Stack

This is the first of three posts about Elastic Stack.

Introduction

At a glance, Elastic Stack is a web based search engine. It’s like Google. For your logs.

Elastic stack contains multiple components.

  • Elasticsearch stores your data, and eats all your disk space.
  • Kibana, the web interface. It looks nice, sends queries to Elasticsearch, and presents the results in a readable way.
  • Logstash, reads logs, receives logs from remote systems, runs the logs through filters to make structured ... [continue reading]
Using systemd timers

You might, like me, once have tried to get something to run on the first Monday of the month, or maybe the last Friday of the month, or something else that’s a combination of a weekday (Mon–Sun) and a «week» (i.e. a date range, like 01–07). The naive approach is to use cron as you would expect it to work:

0 0 1-7 * 1 /usr/bin/foo 

The surprise comes when this makes foo ... [continue reading]

Spicing up your own access with capabilities

I’ve always had a bad conscience about the audit trail on the servers I manage. Sure, we use personal accounts and sudo, so we know who ran every command. Unfortunately, the command in the sudo log is often just “bash”.

The reason for this is simple: It is quite awkward to work in the shell when TAB completion doesn’t work. You want to read the error log in /var/log/httpd? Too bad, the directory is off limits for normal users. So ... [continue reading]

Adventures in bash - catching several exit values in a piped set of commands

All in all, very odd, bash continues to be the most bizarre of languages, convoluted, twisted, but with strange solutions thrown in just when you are about to give up hope entirely.” (forum post at Techpatterns )

When re-working a database backup script at one of my customers I stumbled onto the problem that I wanted to have both proper error handling and at the same time avoid filling the disk.

The code providing the challenge was ... [continue reading]

PaaS Play

The intention of this post is to get oneself kick-started into playing with Platform as a Service (PaaS) by interacting with a lab environment that is running in a VM on your local machine. It relies heavily on other parties (OpenShiftOrigin, jmorales, Red Hat and JavaZone) ... [continue reading]