How would a sysadmin calculate sysadmin day?

168 views Asked by At

Sysadmin day is the last Friday of July.

Sysadmins tend not to stray too far from the terminal, where they belong.

Sysadmins grok man {,/usr}/bin/*.

Sysadmins sometimes stray into interpreted languages found in /usr/bin/*.

3

There are 3 answers

1
Dan Garthwaite On

This sysadmin came up with:

date -d $(date +%Y)-07-$(ncal -d $(date +%Y)-07-01 | awk '/^Fr /{print $NR;}') +'%F'

after @tuberous-potato's answer I came up with

echo $(date +%Y-%m)-$(ncal 7 $(date +%Y) | awk '/^Fr/ {print $NF}')
1
Tuberous Potato On
cal 7 $(date +%Y) | awk '{print $6}' | grep . | tail -n 1
0
redbmk On

Not exactly a one-liner, and building off the other answers - this one will get the next sysadmin day rather than just the one for this year.

#!/bin/bash

sysadmin_date() {
  year=$1
  echo $year-07-$(cal -h 7 $year | cut -d' ' -f6 | grep . | tail -1)
}

next_sysadmin_date() {
  this_years_sysadmin_date=$(sysadmin_date $(date +%Y))
  next_years_sysadmin_date=$(sysadmin_date $(expr $(date +%Y) + 1))
  today=$(date +%Y-%m-%d)

  [[ $today > $this_years_sysadmin_date ]] && echo $next_years_sysadmin_date || echo $this_years_sysadmin_date

  [[ $today == $this_years_sysadmin_date ]] && >&2 echo "Happy Sysadmin Day! "
}

next_sysadmin_date