Scripting My Way to Success

Written By: Jake Bauer | Posted: 2020-06-08 | Last Updated: 2020-06-08

Something that I love about *nix systems is the composability of all of the different available tools allowing for very quick prototyping, fast and easy one-liners, and efficient text processing. I thoroughly (ab)use this to get nearly everything done.

Yesterday, when I was curating my blogroll, I needed a way to update the list of blogs and feeds I follow on my links page. Of course I didn’t want to do this manually since that would be a huge pain. Instead, like whenever I encounter a problem, I turned to scripting. I came up with a script I call generate-blogroll.sh (view the script here) which composes the export functionality of newsboat, the standard awk, cut, tr, sort, and sed utilities along with vim/nvim’s scripting abilities and rsync for uploading the changed files.

The script basically goes through the exported OPML file from Newsboat, breaks each line up into a title, html URL, and feed URL, and then replaces the content of my blogroll page with the new, auto-generated list. Once that’s done, it uploads the exported blogroll.opml file and the newly compiled links.html page. It’s not portable to other websites but that doesn’t matter at all because it’s not supposed to be. I’m not creating a tool for someone else to use, I’m hacking out a script to perform a simple, repeatable function which would otherwise be a pain to do manually.

I created and refined the script over the course of about 30-60 minutes of actual work and, in doing so, learned about how to properly use vim’s scripting abilities, practiced my POSIX shell scripting skills, and had a bunch of fun.

That’s the beauty of scripting and the *nix environment. Any time I encounter a similar problem, I write a script to handle it for me. Need to parse stats from a log file? Script it. Need a way to download the content of an entire website? Script it. Need to test how fast a program runs, then average the runtimes? Script it. Need to generate an entire website from markdown files? Script it (I did for this site!).

In addition to the blogroll script, I have a script to compile this website, a script to publish new blog posts, a script to update the site’s uptime display, and even a script to handle uploading files to my webserver. Those are just the scripts for this website! Some of them need to be rewritten for portability to other *nix systems, and some are from when I first started this site so they’re not as good as my more recently-written scripts, but that’s alright because they do the thing they’re supposed to do and haven’t failed me yet.

Scripting is also great for saving time at work; the more time saved doing menial tasks, the more time can be spent doing interesting things. Plus, you get to show off in front of your co-workers and that’s always a bonus.

The next time you have a menial task to do, even if it’s just a small one, give scripting a shot. It doesn’t matter whether or not it saves you time in the long run (unless this is a critical task, then you should probably care), do it for the fun of it!

This is my thirty-ninth post for the #100DaysToOffload challenge. You can learn more about this challenge over at https://100daystooffload.com.