Quarrying

Charly's Column – Smorgasbord

Article from Issue 207/2018
Author(s):

Sys admin columnist Charly Kühnast has an electronic note box in which he collects ideas and small snippets of code. He calls it his "quarry" and is taking this opportunity to offer up some collectors' items to regular readers.

My life as a geologist started at a time before Git. Originally, I collected code in my "quarry" if I suspected I would need it again one day. Meanwhile, I hoard artifacts from configuration files, keyboard shortcuts that I can't remember for various shells, and names of tools I want to try.

Usually, none of them appear on this page, because each note contains no more than a few lines of text. That's a pity, so today I'm serving up a wildly mixed selection of notes in the hope that everyone will find something new.

The first note is a configuration snippet for Postfix. Many readers will be familiar with email featuring subject lines straight out of hell:

AW:Re:AW:Answer:Re:AW: <Subject>

The following line, built into Postfix's header_checks.cf, shortens the mess to a civilized re: <Subject>.

/^Subject:\s*((Re|AW|Answer):\s*)+(.*)$/REPLACE Subject: Re: $3

Sys admins live in the shell, mostly Bash. There, they often have to do things with root privileges. Switching there, be it permanently (su) or just once (sudo), is annoying. The Bash alias

alias iddqd='sudo su -'

not only saves a few characters, but also proves that its initiator is, first, a nerd with dubious humor and, second, no longer a young man. (The sequence iddqd enabled God Mode in the Doom shooter game in 1993).

The next alias does things in a different, but also smart, way:

alias but='history -s sudo $(history -p \!\!) && sudo $(history -p \!\!)'

It is medicine for the "Permission denied" disease that every forgotten sudo reliably triggers and is fixed as soon as you type doch (of course!). The shell then runs the failed command again, but preceded by sudo. Typing sudo!! would have the same effect, but that requires three more keystrokes and is less cool.

Properly Appended

Searching and replacing in the last entry of the Shell history helps laziness win an important battle. For example, if you typed tail /var/log/syslog, but actually wanted to see the end of /var/log/mail, then appending

^syslog^mail^

replaces the wrong substring. Bash runs the modified command immediately.

Ah! My "tools" list also includes calcurse, a console-based calendar available in almost every distribution. It imports third-party calendars in the common ICS format, supports scripting, and provides information on upcoming appointments in several ways (Figure 1).

Figure 1: Thanks to calcurse, Charly didn't miss his Friday noon lunch appointment and put on his black belt punctually at 7pm.

I have just found another piece of paper that says: "Change the note box to SVN." It's from 2006.

The Author

Charly Kühnast manages Unix systems in the data center in the Lower Rhine region of Germany. His responsibilities include ensuring the security and availability of firewalls and the DMZ.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Charly's Column – httpstat

    Httpstat is a special stopwatch you can use to discover how long web servers take to serve up a static or dynamic HTML page. Visible performance lags indicate optimization potential for the server.

  • Charly's Column – The Fuck

    In the 25 years of Linux kernel history, a huge amount of code and many comments have accumulated. They can be explanatory, enlightening, funny, or even profane. Charly prefers to do things differently, so he types fuck in the shell.

  • The sys admin's daily grind: Tiger VNC

    Sys admin columnist Charly enumerates the computers in his household and makes it clear that commuting between them would be an unreasonable burden on his personal energy balance. Instead he lets a tiger go the distance for him.

  • The sys admin’s daily grind: Sysdig

    In this issue, sys admin columnist and tool veterinarian Charly Kühnast invites Sysdig, the jack-of-all-trades among system diagnostic tools, into his surgery for a quick checkup. The project promises to unite the functionality of lsof, iftop, netstat, tcpdump, and others.

  • The sys admin's daily grind: colorls

    The first time in our lives we got to a black-and-white Linux or Unix shell, most of us probably typed ls first. In a mixture of nostalgia and the knowledge that life is colorful, columnist Charly Kühnast plays a colorful trump card with colorls.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News