Is This The Most Important Script You’ll Ever Write?

Is This The Most Important Script You'll Ever Write? 1 Since my first IT job ever, I’ve taken part in a tradition started by the guy I was replacing. A tradition known to us as, and something people in my local Linux Administrator community have kept with for well over a decade now.

The Most Important Script You’ll Ever Write?

The first time I saw it it was written in Perl, I’ve since written them in Bash, Java and now Javascript. I’ve just seen one written in AWK. Some are cleverer than others, some just do the bare minimum. Some are executed by hand, others are run each time a new terminal is opened thanks to .profile, .bashrc or whatever’s managing your shell environment.

Well What Does It Do?

Quite simply the most important script you’ll ever write calculates the difference between two dates. Today, and your last day of work. The day you escape.. Where to? Who knows, perhaps a new job, a new country, either way somewhere significant!

Mine is currently a node.js app, and it has a bug, it hasn’t taken in to account a bank holiday, but it does the job.

free:~ rus$ node escape.js
Escape in 18 days.
Working days left: 15

Another takes in to account even minutes so he knows how long he’s waiting!

16:03 < woduf> 004 days, 00 hours, 57 minutes

How complicated you want to make the most important script you’ll ever write is up to you, but the sentiment remains the same!

Examples Of The Most Important Script You’ll Ever Write


function workingDaysBetweenDates(startDate, endDate) {

// Validate input
if (endDate < startDate) return 0; // Calculate days between dates var millisecondsPerDay = 86400 * 1000; // Day in milliseconds startDate.setHours(0,0,0,1); // Start just after midnight endDate.setHours(23,59,59,999); // End just before midnight var diff = endDate - startDate; // Milliseconds between datetime objects var days = Math.ceil(diff / millisecondsPerDay); // Subtract two weekend days for every week in between var weeks = Math.floor(days / 7); var days = days - (weeks * 2); // Handle special cases var startDay = startDate.getDay(); var endDay = endDate.getDay(); // Remove weekend not previously removed. if (startDay - endDay > 1)
days = days - 2;

// Remove start day if span starts on Sunday but ends before Saturday
if (startDay == 0 && endDay != 6)
days = days - 1

// Remove end day if span ends on Saturday but starts after Sunday
if (endDay == 6 && startDay != 0)
days = days - 1

return days;

var date1 = new Date();
var date2 = new Date("08/29/2014");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log("Escape in ", diffDays, " days.");

var workdays = workingDaysBetweenDates(date1, date2);
console.log("Working days left: ", workdays);


Thanks to woduf for the following awk snippet!

awk 'BEGIN { print strftime("%j days, %H hours, %M minutes", mktime("2014 08 15 17 00 00") - systime() - 89940) }'


Thanks to xhae for the following HTML/JS combination!



Thanks Huw!

#!/usr/bin/perl -w

use strict;
use Date::Manip;

my $leave = "14th June 2013";
my $escape_date = ParseDate($leave);
my $day = ParseDate("today");
my $count = 0;

do {
$day = DateCalc($day, "+ 1 day");
} while (Date_Cmp($day, $escape_date) < 0); print "Only $count day",$count>1?"s":""," to go\n\n";


Thanks woduf. Note, this works fine on Linux/GNU but not so fine on Mac/BSD

d=$(($(date +%s -d '2013/09/27 17:00:00') - $(date +%s))); echo "Escape in $((d / 86400)) days, $((d % 86400 / 3600)) hours"

Have you ever written an Whether you love your job or hate it, changing job can be a significant life decision and it helps to add fun to the seriousness of it! Please send me examples of your most important script and I’ll add it to the list!

Google Is So High On Adverts It’s Forgotten How To Search The Internet

So, I really like the song Papua New Guinea by Future Sound of London, so on a whim I decided to try and see if there were any Linux Sysadmin roles going over there, I think there’s a huge oil industry out there and they must use computers, right?

linux systems administrator papua new guinea

Turns out the first search result returned matches because of the png file extension? Ok, that’s the TLA for Papua New Guinea but what .. that’s the most relevant result? Really Google?

I expect, with Google’s complete lack of ability, to probably end up page 1 for linux systems administrator papua new guinea even though this site is predominantly about beefburgers nowadays and not linux systems administration or Papua New Guinea!

I keep running in to stuff like this as I do fairly esoteric searches so I’m going to continually update this post with screenshots as I go (if I remember ( unlikely ( As an aside, it would be really cool if WordPress did bracket highlighting like VIM does … ) ) ) … moves to WordPress!

As you can tell has undergone a fairly hefty overhaul and is now being managed by WordPress! This offers several advantages to me namely

  • ease of maintenance (someone else is writing the code!!)
  • code i write is now usable by other people
  • learning wordpress properly is a new job/career skill
  • no more lucene bridge! (it broke a lot anyway)

All the content has been migrated, but as you can see, the theme is a standard wordpress skin, so lots to do still!

Technorati Have Crappy Systems Designers

I’ve signed up to Technorati and to prove I own this blog they want me to post an entry with this code in it:


or maybe this code


They don’t seem to be sure and the email they sent me and their website both say something different ..

Most sites that are better, such as Google or even MS Live/Bing/Bling/whatever they’re calling it this week ask you to create a file on the server, but noooooooo Technorati are forcing me to actually make a post advertising their service .. I really hope it has a happy ending!!! 😉

Damn caffeine

Well, I guess I’ve already broken one of my New Years resolutions although I don’t feel too bad about it.

After a long stint of only drinking water in pubs (really bloody annoying) I had a diet coke .. not the end of the world. The spirit behind that resolution wasn’t really to completely give up caffeine anyway, but to stop having 8 cups of coffee a day, so I don’t feel too bad about it!

New Years Resolutions

A lot of people hate the idea of new year resolutions, but if you want to make some changes and the fact it’s the start of a year will give you motivation, then so be it! Lets see how many I keep in 2009!

* Give up smoking
* Give up caffeine
* Stick to diet and gym
* Less red meat and fatty meats
* No takeaway pizza, McDonalds or Burger King
* Attend martial arts classes more regularly
* Join a yoga/pilates class to improve posture/flexibility
* Visit another contenant

Last year my resolution was to give up McDonalds, I only wavered once when stranded at Liverpool St. Station!