Monday, February 5, 2018

Drinking on a budget: Dollar Tree martini glasses!

We had a very nice set of (I think) six martini glasses, some well-known brand, that we bought as a set perhaps somewhere around five years ago. Every year or so, I accidentally break one of the glasses by dropping it, or the dishwasher decides it's time to crack one of them. So now I'm down to one and it was time to restock. But, I'm on a budget here in Miami. The solution: Dollar Tree!


What could be simpler? They look great. They hold as much as our previous martini glasses, though they look a tiny bit smaller. They also seem a bit sturdier as far as glass and stem thickness. They clean up very nice in the dishwasher. And they're only a dollar each. I'm sold!

I think we're not the only ones sold on Dollar Tree martini glasses. We went to a very famous local restaurant recently, one known for crab claws, and they served us a round of cocktails in glasses that looked suspiciously like these ones. Can't say that I blame them, especially if these are sturdier than average.

Thursday, February 1, 2018

Linux: Redirecting or Silencing Script Output

I've been writing shell scripts on *nix systems for more than twenty years. You'd think that by now I'd have this memorized, but I don't. Since I'm tired of looking it up every time, I'll post this here so that it can help jog my memory next time around.

Repeat after me: redirecting stderr and stdout is easy.

To run your script while silencing any and all possible output, execute it like this:
./runscript.sh > /dev/null 2>&1

To silence it only when it runs via cron, to make it not send you an email after it runs, put it in your crontab like this:
0 5 * * 1 /home/aiverson/script.sh > /dev/null 2>&1
(all on one line)

If you're running a command inside a script and you want to capture both possible errors and standard  output in the same way, so that you can parse it easily, do this:
OUTPUT=`lynx -dump "http://website" 2>&1`
If you don't add the 2>&1, any error message returned by lynx is sent to the active window running your script, instead of into the $OUTPUT variable.

Sunday, January 21, 2018

Linux: Scraping web output with wget

This is probably a tip that smarter folks than me know already, but I just ran into this today and decided I'd write it down for future reference.

I'm writing a simple unix shell script that scans the web interfaces of a bunch of internal servers, looking for a specific error message. Very light touch, fairly simple stuff.

Lots of simple stuff like this:
lynx -source "http://servername.int.local" | \
grep "error code"

It turns out that the server I need to install this on doesn't have lynx installed. It does have wget, however. But wget defaults to dumping the output into a file instead of to standard output, which is annoying when you don't actually care about saving the output.

Unless you do it like this:
wget -qO - "http://servername.int.local" | \
grep "error code"

That makes these two bits of sample code (one with lynx, the other with wget) work exactly the same way. The "q" flag is to quiet wget's normally verbose output, and the "O -" flag is telling wget to dump the output to stdout ("-") instead of to a file.

Which one is faster? In my entirely non-scientific testing, lynx seems to be faster. My suggestion is that if you can, test. Or just use lynx if your system has it installed (or if it can be installed), and use wget as a backup only. (And I didn't even really get a chance to test curl. Sorry!)

For now, I've got a solid workaround to get my script to work on a server that doesn't have lynx and where I'm not an administrator.

Thus ends today's lesson in stupid shell script tricks.