Apparently a handful of customers using Cloudflare for DNS, and specifically CNAME records experienced a brief outage of name resolution services on New Year’s. I found the reason why to be rather interesting. Devs at cloudflare assumed time can’t move backwards… An understandable assumption but actually faulty because of leap seconds… Anyhow, if you do programming you might find the root cause analysis for this hiccup to be interesting and informative:
Well worth a quick read. No, unfortunately it didn’t have anything to do with Dark Matter and/or what happens were a black hole and a Delorian traveling at 88 mph suddenly to meet while Superman flies around the planet at light speed. But, it is still curious enough all the same. Happy New Year… Sanitize your outputs…
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/2016 – Someone 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…)
I have been learning a ton of PHP lately in an effort to build a significant amount of custom functionality into a Drupal website. As I am not a developer by trade it has been a steep climb upward. Lately I have been refactoring a lot of my code using functions. Being a noob however, I ran into some issues in that I didn’t understand how PHP scoped the usage of variables.
Case in point, I had written a function to generate a bunch of variables dynamically based on some input into the function, but I wasn’t able to use those variables outside of the function. (more…)
To make this comparison we need to first consider the problem that both approaches help us to solve. When programming any system you are essentially dealing with data and the code that changes that data. These two fundamental aspects of programming are handled quite differently in procedural systems compared with object oriented systems, and these differences require different strategies in how we think about writing code.
Source: Procedural vs Object Oriented Programming
As I have been learning Powershell I have seen numerous sources state over and again that Powershell is a highly “object oriented” language. Not having any background in programming I have been really curious what was meant by this. The above article explains it nicely. It starts out discussing ColdFusion specifically but the bulk of the article is primarily explaining the general concept of Procedural vs. Object Oriented programming (as the title states) and reading through it has helped me understand why powershell works the way it does. Having a basic grasp on this concept should help me out immensely and I would recommend it as a short read for anyone else delving into Powershell, particularly if you are like me and don’t have a strong programming background.