Linux Script sample

I spent part of the morning trying to figure out a problem on a Linux machine.

The problem is
  1. I like the desktop background to switch among several nice backgrounds in a folder of pictures that I keep
  2. The XFCE desktop environment I'm running does this
  3. The XFCE desktop environment keeps a list of backgrounds in a text file.
    This file usually appears in ~/.config/xfce4/desktop/backdrop.list
  4. I don't want all the pictures in the folder in item (1) are on the list in item (3), but I want some of the ones I've added to the folder to be added to the list
  5. The whole process in item (4) would be easier if I could generate a list of files that are in the folder but not in the list.
Happily for me, the files I'm considering could be found by searching for '*.jpg' filenames in a specific path.

Anyway, this is the kind of task that ought to be easy in a scripting language. And the Linux environment I'm running has lots of scripting languages available.

I tinkered with the results of a simple find command, not liking the problems I ran into trying to execute a grep and parse the results.

Then I realized that what I wanted to do, I could do in a for loop.

I needed to use a simple find command to generate a list of files, and use the loop to look for each filename in the backdrop-list file. If found, I would print out one thing. If not found, I would print out something else.

This loop looks like this, typed in all at once on a single command line:
sj@hostname ~ $ for i in `find ./pathTo/pictureFolder/ -iname "*.jpg"`; do if grep -q $i ~/.config/xfce4/desktop/backgrop.list ; then echo "Found file $i"; else echo "Did not find file $i"; fi; done;
While a little complex to type in, this does the trick.

But I realized that I wanted to be able to repeat this, and I wanted to store the resulting lists of found and not-found files.

I decided to turn the complex command into a script file. I also decided to put the results into a pair of files in the /tmp folder.

if [[ -e /tmp/pic-found ]] ;
   rm /tmp/pic-found;

if [[ -e /tmp/pic-notfound ]] ;
    rm /tmp/pic-notfound;

for i in `find ./pathTo/pictureFolder/ -iname "*.jpg"`;
  if grep -q $i ~/.config/xfce4/desktop/backdrop.list ;
      echo $i >> /tmp/pic-found;
      echo $i >> /tmp/pic-notfound;

sort /tmp/pic-found > /tmp/pic-found_sort
sort /tmp/pic-notfound > /tmp/pic-notfound_sort

It's not beautiful, but it does what I want.

And, when I want to spend an hour browsing through pictures to add to the background-image list tonight, I'll have a much better idea of where to start looking. Instead of spending time looking at the 200-or-so pictures I've already added, I'll be able to look at the ones that haven't been added yet.

It's a small thing, but a little scripting reduced my work-load. And by more time than I spent working on the script.


Weekend reading: Genesis

I've been spending much time, recently, reading the Christian Bible. Most recently, the book of Genesis.

In previous readings of that section, I always thought of it as a history. A little bit of background; a remembrance of the ancient roots of the faith.

This time around, I keep noticing the relational aspect of the narrative.

The narrative starts with God as all-powerful Creator. He speaks, and the world springs into existence.* First there is a bright explosion of energy, then the Earth and Heavens are separated. Night and day are separated, then land and sea. Plants, trees, animals, birds, fish, insects, etc., are all made by Him.**

Yet instead of God being a distant observer, the narrative has God wanting to relate to His creation.

Man and woman were created to live in a peaceful garden in a childlike state. At times, they had the opportunity to commune with God in the garden.

The garden had many pleasant things. Yet there was a temptation to gain some forbidden knowledge, and enter into a more-adult situation.*** A tempter speaks, the sin is engaged in, and the created people felt shame.

They hide from God when He wants to commune with them. God knows, gets the man what happened. The man points to the woman, who confesses and reveals the source of temptation. Then God speaks a punishment over the tempter, the woman, and the man.

This whole sequence can be thought of as a coming-of-age story with a tragic ending.

Many of the troubles of human life are mentioned in the curses. Humanity and the Tempter will always be at odds. The pains of childbirth, the push and pull of desire and authority between man and wife, and the hard work of subsistence farming are all mentioned.

Yet embedded in the curse is a promise. The struggle between Tempter and humanity will one day end, and the Tempter will be the loser.

The main characters leave a childlike, protected state and have to go forth into a harsher environment. They don clothes for the first time. (The fig leaves must have seemed a good idea at first; don't they know that fresh fig leaves have irritating oils? God upgraded them to fur coats...er, animal skins.) They begin the work of producing food and raising children.

I can't help but wonder: was the forbidden fruit the reason for the expulsion from Eden? Or was the desire to hide sin the reason for expulsion?

I notice that there is no resolution to the tension between sinful humans and Creator. The relationship is harmed, but not destroyed.

It's a beginning that is both simple and profound.

*An alternate, if simplistic rendering of the "Big Bang" theory is that God said "Let it be!". And with a big "Bang!", it was.
Perhaps this isn't as non-scientific as it first appears.

I think one of the core elements of the modern Big Bang theory is that there is no scientific way to explore what preceded the moment of beginning.

**As a thought experiment, compare the list of created items in the first chapter of Genesis to the panoply of deities and deity-symbols in ancient Egypt.
Assuming Moses edited the final form of this story for use by the Israelites, recently departed from Egypt. Is it any surprise that the Creation narrative mentions the Earth, the Sun, the Moon, and every kind of living thing as created, subsidiary beings?

***Was the sin eating a fruit that had been forbidden? Or is forbidden fruit an image of something that is hard to describe in human language?
This feels odd to ask, but I wonder. I also wonder if the core meaning of the story is harmed by that question.


Internet Humor (homeowner edition)

Saw a not-too-surprising article on finances yesterday.

That article was written by Megan McArdle, and gave some good advice about the cost/benefit questions involved in homeownership.

However, one of the commenters managed to produce a very funny parody of the typical "bad example" of homeowners turning their house into a money-sink.

After slaying our ancestral enemies and throwing their corpses from the battlements of my clan's ancient fortress - and then surviving the deadly politics of just who would rule from its heights me and my wife were finally home owners.

We could handle all the life and death struggle of owning property. Siege preparedness, check. Keeping secret passageways to ourselves, check. Challenges from people destined by the prophesies of obscure gods to rule in our stead, check. Personal finance? No.

I got a HELOC to do some repairs and the wife was riding me to have the crenelation spruced up. Our big mistake? We dipped into it again to pay some dowries and hire some mercenaries to deal with this whole Ogre infestation thing.

Never borrow from gnomes against the seat of your power for things that you don't use to increase the value of the demesne. Now it seems like every third fowl we squeeze from our serfs go to those guys. Sometimes I just don't think it is worth it.

[some line breaks and punctuation added --ed.]
I found the comparison between a debt-riddled noble of a past time and the debt-encumbered homeowners in modern America to be funny, and pointed.


Speaking of springtime...

Snow on the 25th of March.

Mostly flurries in the morning. Then more flurries, plus wind, that seriously reduced visibility.

No need to shovel it. Yet.

Is there a place I can return this instance of Spring, and exchange it for a better one?



Spring has sprung.

At least, the Sun will be visible for slightly more than 12 hours today.

The Equinox has passed, the season is turning. I even saw a Robin in my yard, which is usually treated as a sign of Spring.

Somehow, I'm not fully convinced.

This past winter included many surprise snowstorms. The daytime temperatures and overnight lows are still showing spikes into the really-warm, followed a day or two later by return-to-wintery-cold.



There's a big NRA convention in Indianapolis this year. I've desired to go to such a convention for a few years, but haven't had one within driving range.

This year, I decided to go.

Then I learned that an honest-to-goodness EMT, with years of experience, is doing a special class. The subject of the class: basic First Aid. (Class is already full, too...) Another good reason to go.

Kelly's class isn't at the Convention itself, but it is aimed at Convention-goers. The idea is that a shooter should go to the range prepared. Prepared to shoot safely, prepared to enjoy themselves.

And prepared, with equipment and training, for the unlikely event of dealing with a shooting accident at a remote gun range or hunting camp.

I'm looking forward to taking the class.

And seeing the rest of the convention, of course.