Standard Mischief

Archive for March, 2009

common bash misconception

If you’ve done any bash shell scripting, you may have come across the need to write data to a temporary file. However, a well-written script should take in the possibility that it will be run more than once at the same time, (the unices being multi-tasking and all that), so you will want to make sure that different processes don’t all write the same data to the same hard-coded /tmp file.

One of the standard ways to do this is to use the bash built-in variable “$$“, like so:

echo $data-to-log >> /tmp/"$$"log.file.txt

And that usually works fine, as long as only one person is running that script per login account. You will, however, have issues if you run the script from the console at the same time that the script is run from your crontab. Ask me how I know.

The common misconception here is the idea that the bash built-in variable$$holds the PID (process ID) of the script itself. That is not true. It’s actually the PID of your bash shell. Therefore running your carefully crafted script more than once at the same time can fsck-up your script output.

A better way, and my standard mischief, is to do the following. First, somewhere up near the top of your shell script create a variable that is unique, like so:

uq=$(date +%s-%N)

backtick people can use this:

uq=`date +%s-%N`

but I like to use the “$()” out of habit because it makes it easier to nestle the commands. Besides, after too much caffeine and staring at a LCD all day, those backticks can be a bit hard to see.

Then, we use this variable in place of “$$“, like so:

echo $data-to-log >> /tmp/"$uq"log.file.txt

What we are doing here is running the date command, and having it show the number of seconds since the Unix epoch back in 01jan1970. Then, we add a dash and the number of nanoseconds. We assign the results of that command to the variable “$uq“. The end result is that unless the two scripts run this command at exactly the same time (probably impossible even if you were trying), the variable $uq is going to be a wholly unique number. When you use this unique number in a filename you can be pretty sure you won’t be clobbering existing data by overwriting an existing file.


2009-03-25 06:35 by Standard Mischief, Filed under:don't try this at home     2 Comments

hacker

My 8-year old nephew, the really clever one that’s unusually quick for his age on the computer, has managed to guess his mother’s password. Of course, having discovered something neat, he had to go tell everyone to inflate his “street cred”. Thankfully, it looks as though he is not getting in trouble for this. His Dad, my brother, was bragging about it this weekend. Mom has learned to pick a password that is stronger than just a number plus a word found in the dictionary.

This nephew reminds me a lot of another one of my nephews from another brother. Besides the quick study of all things binary, I’ve watched him get into a hyper-focused bubble-like trance when learning marksmanship with my bolt-action .22. (When teaching kids like this, make sure to give them one round at a time.)

Seeing these kids excel at tasks that they self-motivate themselves on, reminds me again that the label “attention deficit disorder” (or any of the other names on the euphemism treadmill) really don’t fit. Nor do I approve the popular remedy of indiscriminately giving these kiddies the functional equivalent of crystal meth in pill form so that they will settle down and focus. (I won’t reject the therapy out of hand, or say it’s never appropriate, but there’s got to be a reason why it’s a very popular prescribed pill, and I think you’ll get a lead on the answer if you just google “homework drug”).

Fortunately, my nephew’s million-thoughts-per-second-yet-still-can’t-remember-to-brush-his-teeth-when-sent-upstairs scatter-brain is tempered by my sister-in-law’s amazing patience-fu.

2009-03-16 23:51 by Standard Mischief, Filed under:deranged rants, not intended to diagnose, treat, cure, or prevent any d     No Comments

like cellaring a wine box

Uncle reminds me about my favorite cheap (but good) booze:

Pikesville Rye is a “Maryland” style rye that used to be made in Pikesville, Maryland. Now it’s made in Kentucky by Heaven Hill. It’s absolutely the very best deal in American Rye Whiskey, and I’m not the only one who feels that way, there are positive reviews all over theses tubes of interwebs.

Until today, I’ve only seen it in 750 ml glass bottles in the $11 to $21 dollar range. Let me assure you that the eleven buck stuff tastes the same as the 21 dollar style sold in the upscale shops.

Today I was out and about and found the 1750 ml size for $22. I almost bought out the stock, as I’m having to go in wider and wider circles to find the stuff, but there’s something about a plastic bottle that screams “rot gut”.

I’m sure that plastic packaging doesn’t affect the taste in any way, but I’m gonna decant mine. Spare me the “winebox is a superior package” comments, plastic is cheap (unless it’s “polymer”).

Pictured also is the coffee scoop to make sure that I only pour myself a single instead of a double by mistake, and a repurposed furikake drinking glass.

Liquor taxes vary considerably from state to state but around here, the cheapest stuff in the whiskey isle goes for $8 per 750 ml and $16 per 1750.

2009-03-14 23:11 by Standard Mischief, Filed under:payola free reviews     No Comments

Well, I was pretty sure I wasn’t all alone out here…

So all the while where I’ve been ranting and raving over my own particular libertarian leaning beliefs, (namely, freedom is good, but giving artificial entities the same or greater rights than natural persons is a really crappy idea), I’ve felt as though I was off in the wilderness, way out from mainstream, and even well past the blue-skinned libertarians and the ostrich-and-dope party.

It gets pretty lonely out here, but at least I know that I’m not completely alone.

Why Corporations Are Not People, And The Unsavory Consequences of Pretending That They Are, by Mike Hoy (of Loompanics fame).

He’s got a 2005 copyright on this essay, the same year I started blogging, so I don’t know who came first, but it’s nice to know one of us has a posse.

Things are busy at work (and that’s a very good thing) so I haven’t fully parsed this essay, but we’re clearly in the same groove.

2009-03-11 23:10 by Standard Mischief, Filed under:deranged rants     No Comments

…they lied, cheated and stole, but you ought to take one for the team

I probably ought not blog drowsy, but here goes…

Kevin talks about people doing the “jingle mail”, by mailing the house keys back to their lender and walking away from upside-down mortgages because doing so is in their best interest.

Why Personal Honor Matters

He quotes someone else saying:

“Can you imagine if you had a same or similar home and your mortgage was half the price?” asks Linda.

This is how it works. Bob paid $420,000 for his home. Then he notices the house across the street, with more upgrades, and is selling for $315,000.

So Bob, who has pretty good credit, decides to buy the cheaper house. He can’t afford both, so then he walks away from his original home, letting it fall into foreclosure. That will hurt his credit, but he’s willing to take the hit for a more affordable home.

“Is it wrong to steal when you’re hungry? That’s an issue that a lot of people are trying to figure out right now,” says Linda.

Caoli is sympathetic, but she doesn’t endorse the practice of it. Other real estate agents we talked to were far more critical, calling them cheaters. They say the banks take a huge hit when their homes foreclose, and in the end, we all end up paying the price.

I’m not talking about lying on your mortgage application (a felony). I’m not talking about lenders fudging the numbers so they can make NINJA loans that they know the seller can’t afford (another felony). I’m not talking about committing fraud by repackaging loans to deliberately hide risk. I’m not talking about swapping favors with your significant-other over at Fannie Mae while holding an office of trust as a Federal congress-critter. I’m not talking about allowing corporate personhood-thingys to lobby and successfully remove regulations limiting “leverage”, and then coming hat-in-hand to Congress because you are “too big to fail”. I’m not talking about going from rosy quarterly report made up of lies and fraud to belly-up in three days.

I’m talking about an individual using legal means to make the wisest possible decision that is in their best interest. You think the bank isn’t looking out for their best interest?

2009-03-09 00:50 by Standard Mischief, Filed under:deranged rants     2 Comments
current.png

Powered by WordPress , Theme Ported to Wordpress by Liu Xun. Original Design by Cathayan