A lot of my bash scripting experience has been, in one sense, relatively simple. I have several scripts that span several hundred lines and do fairly complex things across multiple systems. From that perspective they aren’t necessarily simple. However it wasn’t until recently that I had to really starting thinking about managing when scripts run and particularly keeping them from “stepping all over each other” when multiple instances of the same script must be run… enter the topic of “Job Control” or “Controlled Execution.”

A common scenario is that your bash script is written to access some shared resource. A few examples of such shared resources:
-An executable file that can only have one running instance at any given time
-A log file that must be written to in a certain order
-Sensitive system files (such as the interfaces file).

What happens if a bash script gets executed once, and then before the first instance finishes running a second instance is fired off? The short answer is typically unexpected/bad stuff that tends to break things.

So the solution is to introduce some job control logic into your scripts. And to that end I want to talk about two methods of controlling job execution that I have started to employ heavily for one of my projects: Simple Lock Files, and the more involved FLOCK application built into most newer Linux distributions. For reference, most of this article is based on a system running Debian Jessie. (more…)

I am working on a project where I need to generate a random value and assign it to a variable…

Initially I was doing this:

var=$(date +%s | sha512sum | base64 | head -c 12 ; echo)

Which was okay until I started executing my script more than once in a short period of time. Suddenly my random variable wasn’t so random and I was getting the same value multiple times in a row. This is a flaw of this method in that it is a hash of the value of the date (represented as an epoch value) at a given second.

UPDATE – 6/28/2016Someone pointed out to me that the OpenSSL method below also relies on the value of the date and time. I am not sure why it doesn’t experience the same issues as just using a sha512sum and, as I have a working method, am not going to investigate it further. I just wanted to clarify for the sake of accuracy. I am not an expert with this stuff.

So I had to can that method and that led me to trying this next:

var=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)

This worked perfectly from the shell. Worked great when I executed a test script from the shell using it. However the PHP script that fired off the bash script would freeze whenever I used this. (more…)

This is going to be very short and sweet as it is primarily just a note to self. I stuggled with getting outbound mail delivery working for some time and finally got it all figured out. Using Exim4 for mail sending I did the following:
(more…)

I had a VM using RAW storage format on a ZFS storage object. I needed to delete the RAW hard drive files but couldn’t find them and the “remove” button was greyed out. One post mentioned using “qm rescan” which then allowed the poster to use the remove button but that didn’t work for me. After some research I found out that virtual drives on ZFS storage aren’t actually files but are “ZVOL”s. After a bit more research I came across the solution below to remove these drives manually. (more…)

For this tutorial I will be walking through how to use a tool called Realmd to connect an Ubuntu Server or Ubuntu Desktop system to a Windows Active Directory Domain.

In the past I wrote an article talking about how to use Powerbroker Identity Services to do the same thing, but the scope of the article was limited to the server version of Ubuntu only. Furthermore, it has since been my experience that PBIS is an unreliable solution at best.

Part of the confusion I have had on this issue in the last two years has been in thinking that there are only one or maybe two ways to make an Ubuntu Desktop/Server OS connect to a Microsoft Active Directory domain and they both used the same underlying stuff. In fact there are more like 10 different ways to do it all using a mix and match of different technologies.

Finally, I don’t like proprietary stuff. PBIS, while having a free version, was still proprietary. Today we will be using a suite of tools called SSSD. SSSD was created by Redhat and it’s opensource. Furthermore we will be using RealmD, which is a “wrapper” of sorts for SSSD that makes it easier to setup and configure. That’s the short of it. Let’s get started. (more…)