Do you manage UNIX machines that are logged into by multiple users? If so, this scenario will be familiar to you: you need to communicate something to your users — a maintenance window, modifications following an update, a policy change, etc, etc.
What do you do? One of these:
At this point, you may be wondering “So? What’s wrong with that?!”.
Well, I’ll tell you…
Let’s start with
/etc/motd (short for Message Of The Day). For those who do not know, it is a text file whose contents are outputted upon user login. It’s a straightforward, elegant mechanism. Alas, it was created in simpler times, when people actually read stuff and you were allowed to respond with “RTFM!” and laugh at them when they didn’t (I miss these days! but I also miss Perl and there’s nothing one can do about either— times changed).
Today, many distros output so many messages upon login by default (and admins do not bother editing these or the scripts that generate them) that users actually train their minds to pointedly ignore them.
_wall_, it’s a util that outputs a given string to the tty (or, more commonly the pts), of all logged-in users. Again, it suffers from the same problem: if a user is happily typing away commands or tailing some log file, he or she may not notice the message at all.
I deliberated whether I should even have to explain why emailing about such things is bad and decided that I should, providing that I can keep it short:
Basically, in the case of policy changes or post upgrade updates, people tend to ignore the notification altogether, even if they did notice it; as to maintenance windows, you can make the message sound important enough by including “ATTENTION” or “MUST READ” (or words to that effect) in your subject line but the question is: when to send this? If you send it ahead of time, people forget all about it by the time it takes place. If you send it just before, people may not see it as no one reads emails anymore (except for me — I love emails). So, after being burnt a few times, you end up sending it several times which is annoying to do but, even more annoyingly — STILL not enough.
Okay, now that I got your attention (well, one would hope), what is my proposed solution?
In 3 words? USE THIS SCRIPT
It’s pretty self explanatory once you run it but I’ll elaborate a bit anyway. (I’m told the most read Medium posts are estimated at around 7 minutes read time so I reckon I’ve got a few paragraphs to spare).
This script uses the toilet and lolcat utils to generate messages that will grab your user’s attentionand the who util to find the tty and pts devices of logged-in users so it can send them said messages.
To illustrate, here’s what it outputted to the terminal when invoked with:
$ ./gmessage.sh “This system will go down for maintenance in 7 minutes” Jesse
That would be kind of hard to ignore, right?
So, this script serves as a pretty good wall replacement (wall will strip all escape/control sequences other than \007, by the way).
As to an alternative for /etc/motd, how about some custom code in
/etc/bash.bashrc (or the equivalent in your interactive shell, BASH isn’t for everyone)?
For example, I’ve added this to
zsh and friends are nice but I like my BASH):
if [[-n $SSH_CONNECTION]] ; then toilet "Welcome to $HOSTNAME" -f future.tlf -t | /usr/games/lolcat echo -en "Here are some things we need to let you know about.\nBlah blah blah and also, tripe, tripe, rubbish\nThank you\n-- root" | /usr/games/lolcat fi
And, here’s the result:
Nice, eh? Let’s see them say they didn’t see that one:)
Both toilet and lolcat support multiple flags so it’s worth glancing at their respective man pages. For toilet, I am using the future font file by passing “-f future.tlf” but if you don’t like it, there are plenty others to choose from.
I installed both from Debian’s official repos and as a result, the fonts reside under
/usr/share/figlet, the location on your box may vary.
Lastly, another awesome use of these utils is generating captivating headers from the comfort of your shell:) I used it to generate the hero image for this post (far faster and easier than any presentation/animation tool I’ve ever worked with).
Happy hacking to all!