Computing Days Between Dates with bash

Needed a quick way to compute the number of days between two dates:

!/bin/bash
# adapted from https://www.linuxforfreshers.com/2019/01/how-to-count-days-since-specific-date.html
 if [ $# -ne 2 ]; then
     echo "USAGE: $(basename $0) start_date end_date";
     exit 1;
 else
   start=$1;
   end=$2;
   echo "$((($(date +%s --date "$end") - $(date +%s --date "$start"))/(3600*24))) days between $start and $end";
 fi

VNC via SSH Tunnel

While I typically use a remote shell, occasionally I’ll need use a GUI remotely.  On the remote machine, create the remote server:

vncserver :1 -geometry 1920x1080 -depth 16 -localhost

This creates a new VNC server for X11 display :1 (:0 is the one created on boot, if not a headless machine).  -localhost ensures that the server does not accept remote connections.  Instead, I use SSH tunneling to provide an encrypted channel to the server:

ssh -NL localhost:5901:localhost:5901 SERVERNAME &

Using -L, we bind local port 5901 to port 5901 on the remote server, which is the default VNC port for display :1.

Tear down the server when finished:

vncserver -kill :1

Using an Existing Desktop Session

To mirror an existing X11 session instead, use x11vnc:

ssh -L 5900:localhost:5900 SERVERNAME 'x11vnc -usepw -localhost -forever -display :0;'

 

PDF from markdown

I like to use markdown for my course syllabus, since it’s quick and easy, and allows easy use of git to make and track updates.

My department requires a PDF version of the syllabus, so I discovered this handy way to convert from github-flavored markdown (at least tables are supported):

pandoc -t latex -o README.pdf README.md

It first converts the markdown to latex, then produces the PDF.