I discovered a large gap in my bash kung fun today - I had no idea how to loop on lines of data in a file.

It turns out that “while data” pulls off this trick quite nicely:


while read myline
  do $myline
done < inputfile

before I lose this hilarious clip…I need to share it

I haven’t been using “traditional” singletons for a couple of years now (Spring craze and all), so the Initialization On Demand Holder idiom, which allows for lazy instantiation of singletons, has escaped me until now.

private static class LazySomethingHolder {
    public static Something something = new Something();
}

public static Something getInstance() {
    return LazySomethingHolder.something;
}

Here’s the explanation, courtesy of Bill Pugh, Brian Goetz and friends.

Found via TheServerSide.

I was sick of typing in username/password for each login (I’m currently working on XP, deploying to a Linux-only env), so I finally went through the pain of following the steps here and set up PuTTY/Peagant public key authentication.

It was a relatively painless setup process, but here are a couple of things to keep in mind when going through it:

  • PuTTY is a pain to update/navigate as you have to remember to load/save during each setting update
  • You can “pre-enter” your remote username by setting “username@hostname” as the hostname
  • authorized_keys file on the remote box should have a mask of 600
  • putty.exe -load “session_name” allows you to create PuTTY shorcuts for each of your connections

My boss is a huge “Big Lebowski” fan, so I had him check out one of all-time favorite YouTube clips - F*cking Short Version of the Movie.

The Stranger: There’s just one thing, Dude.
The Dude: And what’s that?
The Stranger: Do you have to use so many cuss words?
The Dude: What the fuck you talking about?


Would you like to create a lively, “top”-like output from some of the monitoring commands in your toolbelt?

“watch” can be of help here, as it can poll your command every X seconds and render its output to full screen.

Try “watch -n1 date” for a demo.

NAME
watch - execute a program periodically, showing output fullscreen

SYNOPSIS
watch [-dhv] [-n ] [–differences[=cumulative]] [–help]
[–interval=] [–version]

I was writing a multi-line batch script with multiple call-outs to Ant and I was confused when it kept exiting after the first call-out.

I’m proud to be rusty at batch scripting, so I’m not ashamed to share the (obvious) fix…

To run a batch program from within the current batch program, use the call command followed by the name of the batch program you wish to run. After the second program is finished, it will return to the command which follows the call command.

If you invoke a batch file without using the call command (from within a batch file that is), control passes over to the new batch program and does not return.

I’m administering a mix of Red Hat and Debian boxes, so this tip from bschmitz comes in handy…

cat /proc/version

Simple thing to do…had to look it up…

kill -HUP `cat /var/run/sshd.pid`

One of my favorite Trac features is the ease with which you can link from Tickets to Changesets and from Changesets to Tickets.

Text input of [256] is interpreted by Trac as a link to Changeset 256, while text input of #256 is interpreted as a link to Ticket 256 - one can’t ask for anything easier to remember.

My only wish would be that linking from Changesets to Tickets would also trigger a Ticket update about a related Changeset commit. I guess I’ll be forced to write that as a Subversion trigger unless I get lucky Googling for prior art.

I stumbled onto this while troubleshooting Putty disconnects on XP…gotta love FAQs w/ attitude.

A.7.12 When I cat a binary file, I get ‘PuTTYPuTTYPuTTY’ on my command line.

Don’t do that, then.

This is designed behaviour; when PuTTY receives the character Control-E from the remote server, it interprets it as a request to identify itself, and so it sends back the string ‘PuTTY’ as if that string had been entered at the keyboard. Control-E should only be sent by programs that are prepared to deal with the response. Writing a binary file to your terminal is likely to output many Control-E characters, and cause this behaviour. Don’t do it. It’s a bad plan.

Check out Jeremy Mates’ reallykill script if you need to effectively kill a processes with a preference for graceful shutdown.

« Previous PageNext Page »