[Semibug] listfile: help your scripts process a list of things
Nick Holland
nick at holland-consulting.net
Sat Jun 7 10:14:44 EDT 2025
If you administer a lot of Unix-ish computers, you want this. I wrote
this a year or so ago, and I'm really regretting having done 20+ years
of Unix administration before having written it.
However, it might take a moment to realize how useful this could be to you.
So, please hang with me a moment here. This is a simple problem that is
usually solved in a simple way:
Problem:
You have a task you have to perform across a bunch of systems. So... you
write a simple wrapper around your script, something to the effect of:
for S in $(cat server.list); do
...some task...
done
And that's stupidly simple, right?
But of course, something goes wrong on a few of the systems, so now you have
to re-run that task against those. But your script was set up for a file,
and a particular file at that...so you edit the file, put the problem
machines in it, re-run. And repeat.
and...you can't comment out a line or add comments to a line.
But...what if instead...you had a little helper script in your PATH that
permitted this:
for S in $(listfile $*); do
....some task...
done
Now, listfile expands your command line to use individual names AND files
that are LISTS of names. for .list files, it ignores commented out lines
and end-of-line comments.
For example, I use this at work to patch systems:
# patchall devqa.list
which patches all the systems listed in the file, devqa.list.
Some of the lines are commented out, most of the lines have comments
explaining who the "owner" of the system is.
if something goes wrong with a couple of them, I fix the problems and
re-run the patching process against those machines with:
# patchall rottenapple broken
and now the individual servers "broke" and "rottenapple" are patched.
.list files can have a list of names and/or other .list files (there's
a limit of five levels of recursion because if you go that far, you
probably have a loop in your list files.
If I wanted to patch ALL my lists, I could do this:
# patchall devqa.list uat.list production.list
OR I could create a list file, "all.list"
+---------------
|devqa.list # Development/Quality Assurance
|uat.list # User acceptance Testing
|production.list # the stuff that makes us money
|ibs jumpbox1 jumpbox2 # Unix team utility systems
|dr-jump dr-ibs # systems at our DR site
+---------------
where we have three lists and five individual systems listed.
What I like about this is it turns a quick-and-dirty script into
something far more "maintenance tool" grade with no more effort at
all. It's a stupidly simple game changer.
More info, and the script itself, here:
https://holland-consulting.net/scripts/listfile.html
(no ads!)
Nick.
More information about the Semibug
mailing list