This article explains how to find the time interval between two Unix time stamps. The default time format in Unix is like this: “Sun 9 Aug 12:50:08 BST 2020”. It appears in many places on the system and is the default produced by the “date” command.
For example, it might appear in application log files, like this::
Start time: Sun 9 Aug 10:05:00 BST 2020
End Time: Sun 9 Aug 12:51:12 BST 2020
This article explains how to subtract one time from the other in Bash, and obtain the intervening time in seconds.
This article explains how to create some simple mathematical shapes with graphics.py, a popular graphics library for Python written by John Zelle. Graphics.py is a single file containing graphics functions such as Point, Line, Circle and Rectangle. In this article though, we are just going to use it to plot single points.
At the top of the page is a blancmange like shape. The program that drew it is at the bottom of the article, if you want to jump straight there. Otherwise, a couple of simpler plots will be demonstrated first, just to show a couple of underlying principles. Continue reading →
Most programming languages offer the facility for making large, compound data structures. For example C, Pascal, Perl and Python. A few simple data types are provided, out of which larger structures can be built. A programmer can store data in a whatever way is most suitable for the application.
Often, a simple list or dictionary will be enough. Read the data in, process it, and print the results out. Perfect. But for a larger or more useful application, more data, and more kinds of data, will need to be stored and processed at the same time.
This article demonstrates the building of a complex data structure in Python. Note: it is not about classes, or object oriented programming, just the syntax for handling complex data structures, made up of lists, dictionaries and simple strings and integers. Continue reading →
Unix users and administrators will be familiar with the cron, unix’s built in job scheduler. It is a good way of running regular jobs eg backups, system monitoring programs or housekeeping scripts. The configuration of cron is quite particular and care is needed when setting up a new job. Your well tested script can behave differently when it is called from cron. Sometimes the differences won’t matter. But sometimes they do, and finding the cause can be tricky.
This brief article describes how many such problems can be tracked down simply by capturing the standard error output properly. In short, make sure your troublesome cron job is not quietly discarding the very information you need to fix it. Continue reading →
A backup script that runs on several Linux systems recently produced the following error:
ls: cannot access '/tmp/sortrq9hq8': No such file or directory
It happens every time the backup runs. Other than the above message, there seems to be no ill effect on the backup, which completes successfully. The ls command did not find a file that it expected to be there.
This article explains how the missing file was created by the Linux sort command as a temporary storage area, how error messages about these files are likely to crop up from time to time, how to reproduce the error, and some background about the behaviour of the sort command on Linux and Solaris. Continue reading →
Ansibleprovides a rich pattern matching ability. Modules like lineinfile can match strings based on regular expressions. Similar expressions are used in Python, Perl and older tools such as egrep, grep, sed and awk.
When attempting to match a string containing awkward characters, an escape mechanism can be used. For example, the dollar character ($) has a special meaning within in a regular expression, being the match for end-of-line. So to match a literal dollar, an escape character, usually a backslash (\), is needed. For example, the regular expression “\$1.65” will successfully match $1.65, without treating $ as end of line.
When processing a string that contains many special characters, the escape syntax can become onerous. One solution is to just “blanket” match the special character, rather than trying to match it precisely. In other words: just use a dot. Continue reading →
Nextcloud is an open source software package providing remote file sharing services. It is similar to Dropbox. But with Nextcloud, you retain ownership, security and control of the shared data. This procedure describes how to build a working Nextcloud service using just 3 commands. It has been tested on Raspbian Stretch and on the Raspberry Pi 4 / Raspbian Buster (this article last updated 14/1/2020)
Note: If you would rather do the installation manually, step-by-step, without the help of a script, please see my previous article “Simple Nextcloud Installation on Raspberry Pi“. It explains how to do the installation in detail, and provides more background information on Nextcloud. Both procedures achieve the same overall result, however.
Note: If you are running Raspbian Buster, then Nextcloud 17 will be installed. For Stretch, it’s Nextcloud 15.
“Link shortening” happens when a short URL, such as http://bit.ly/2bo3XYY, points to the same web page as a longer link, such as https://en.wikipedia.org/wiki/BBC. Short links are often used where there are a limited number of characters available, such as an SMS text or a Twitter post. Short links are also quicker to type and neater than the associated full length links.
Two of the main providers of short links are Bitly and Google (Goo.gl). For example, I used Bitly to create the short link in the above paragraph. However, if you have a Raspberry Pi (or any kind of Linux server), you don’t need to use a provider. You can create your own short links. This article explains how. Continue reading →
In Perl, hash (associative array) sorting is a common and easy practice. Sorting values by key is easy. And so is sorting by value. But how do you sort the values of a hash by key? One answer is to use a hash slice. Continue reading →