Awk lives

Awk is pretty ancient (1977) but is a nice tool to know for text processing. I’m no expert, but I do use Awk from time to time for various simple tasks. A second edition of The AWK Programming Language is coming out in October and it looks interesting based on what I read through on O’Reilly. This article shares some of the highlights including a chapter on data analysis and an updated simple version of Make in Awk.

Read More

Bash template

I’ve not been doing much bash scripting recently. So, when the need arose to create some simple scripts, I did some quick refresh on some things that make scripting better/faster/easier. A nice resource I found had some opinionated advice on bash and a really nice template that I’m going to use as a starting point for my scripts. It looks like this: #!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi if [[ "${1-}" =~ ^-*h(elp)?

Read More

Shellcheck

Shellcheck is a handy tool for working with bash scripts. It does a nice job of doing a sanity check of bash script against a set of rules and is simple to use. As a quick example, consider this very simple script: #!/bin/bash A="some value" echo $A echo "${A}" echo "${B}" This script will do what you think it should but has a few problems. Running shellcheck on this script produces some simple output with suggestions to improve the script:

Read More

Cloud command line

I use AWS occasionally and on those occasions I almost always discover something new and interesting. Today’s discovery is fairly prosaic but interesting in a number of ways: AWS CloudShell. I’m running a little behind the times here as this has been around for well over a year and I’m somewhat familiar with the GCP and Azure versions of the same basic thing. AWS CloudShell is, as the name says, a browser based shell that is integrated into AWS.

Read More

Alias for post creation

Hugo has worked out well for creating this blog. To make it even easier, I wanted to make creation of new posts simpler. To date, I’ve basically looked at the last post and then created the next one in sequence by using the command hugo new ~/myblog/post/content/091.md, for example. To automate that some, I created a bash alias that looks like: alias newpost='hugo new ~/myblog/content/post/$(printf "%03d.md" $(expr $(basename $(ls ~/myblog/content/post/ | tail -n 1) .

Read More

Blog restructure

I felt the need to renumber my blog posts file names from a date (e.g., 20211222.md) to a sequence (e.g., 087.md). Hugo does a nice job of putting posts from the same date into a folder labeled for that date, so the date numbering was restrictive if I wanted to create two posts on one day (admittedly, a rarity). A number also is a nice way for me to keep track of how many posts I’ve written since I started doing this again.

Read More

Last arg

Reusing the last argument is something that I frequently do when working in bash. I’ve more or less committed the !$ history expansion to memory. This makes it really easy to do something like touch myfile.txt and then immediately edit it with vim !$. I learned about another way to do this using escape-dot today. It works the same way. It’s nice to learn new stuff but i’ll probably stick with !

Read More

Scripting Secure Ubuntu Server Creation

If you create a cloud virtual machine and run it for anything more than a few minutes, it quickly becomes apparent how much nefarious activity goes on. You will get hit with brute force attacks on all of the known ports (and some unknown ones) pretty much continuously from the first minute. I don’t know that there is much that cloud hosts can do about this. They have known IP ranges and I would assume that attackers constantly troll those known ranges.

Read More

Bash strict mode

I’d been starting bash scripts with set -euo pipefail. I don’t really know where I got it from but it was something I’d picked up over the years. Aaron Maxwell has an excellent description of how this works and why it is a good idea. I also learned about the Internal File Seperator setting in that blog post and why that is a good idea. Read his excellent post. The net is that you should start your bash scripts with the following:

Read More