Qubyte Codes

How I schedule posts using atd

#bash

This blog is built with a static site generator. The generator, the markdown source files, and the generated HTML files are all kept together in the same git repository. Every time I commit a change, a pre-commit hook runs the generator and adds the generated HTML, so that the blog entries are always up to date. Then the changes are pushed up to GitHub.

On the server (running Linux), NGINX is hosting a folder containing the files to serve from a clone of the repo. To publish a new post, or update an old one, all I have to do is pull the changes from GitHub. Publishing via the terminal allows me to use a one liner to schedule the publication. Many know about cron for scheduling repeated tasks, but fewer are aware of atd, which is for one time scheduled tasks. The one liner I use is:

echo "git -C /absolute/path/to/repo pull origin master" | at 07:00 tomorrow

at accepts input through stdin, which is why I've echoed the command and piped it. One big gotcha is that you have to be aware of the timezone your machine is configured for. I have mine set to UTC, and schedule according to that.

There are companion utilities to manage scheduled jobs. The man page for at is extremely good, so I won't try to better it. The purpose of this post is to show you that it exists and how simple (especially when compared with cron) it is to use. You can use it to schedule pretty much anything!