Automation

Trying to automate all the crap we have to do since corporate policy doesn’t allow static service account/password combos any longer. Hey, no problem, we could use RSA keys. Except, hey, Windows doesn’t do that. So now we’re spending $FOO on some stupid utility to manage, in bulk, Windows service account logons. And $FOO is cheaper than figuring all of that out on our own. Oh, and for some reason one of the bog standard VMs we’re issued isn’t responding to RPC even though the other fifty or so do.

Who knows why? It must be a party!

Oh hai! What about all of the *nix boxes that need their sandbox tokens refreshed? Cool, we could use SSH from the same Windows box to run commands as a user remotely. Of course, Microsoft forgot to roll in an SSH client into their operating system. Oops!

“No problem, use PuTTY,” they say. And then you figure out that PuTTY is an utter dick about handling RSA key files. No way! Who would have ever thought doing something completely routine on any other operating system would be such a turdgargle when it comes to Microsoft?

How to solve? Install a bash client on the Windows box and then just do stuff right. Yet another afternoon lost to the joys of Microsoft. When can my employer start billing Redmond for my time?

Working smarter, not harder

New-to-me Windows DOS commands that are equivalent to bash commands that I always use. Another in a long series.

runas [1]
Equivalent to sudo, allows one to run commands as a different user assuming one knows the password for that user
pushd [2]
Maps a network location as a volume
popd [3]
Drops that mapping

Use them in combination and you’ve got remote filesystem mapping from the CLI amongst other ways of doing work on remote machines without having to actually remote out to them. I’ve learned three things today. Can I take the rest of the week off?

[1] http://technet.microsoft.com/en-us/library/bb490994.aspx
[2] http://technet.microsoft.com/en-us/library/bb490978.aspx
[3] http://technet.microsoft.com/en-us/library/bb490969.aspx

bash on Windows

My rose for the day [so far].

On Windows you can use the command explorer SomeDirectory and Windows Explorer will open with the view set to SomeDirectory, assuming one exists as a child of the current working directory. The same holds if you want to jump around the tree a bit. explorer \foo opens foo in the root of the current volume and explorer D:\foo would open D:\foo even if you were currently in the C:\ volume.

Which, once I learned about the awesomeness of Console2 [1], I’ve always created an alias mapping ‘exp’ to ‘explorer’. Because, you know, saving five whole keystrokes seems like a major win. Yes, I’m lazy.

I’ve since switched from the default cmd.exe as my Windows CLI to the bash shell that comes for free from Git [2]. All kinds of awesomeness ensue. On shortcoming however is that *nix paths are separated by ‘/’ while DOS paths are separated by ‘\’. Also, the Git bash refers to volumes using the ‘/c/’ notation while DOS uses ‘C:\’ notation. All of which means I still have to remember which frickin’ shell I’m using when on a Windows box. At least if I want to use the CLI to open Windows Explorer to a specific location, which I often do.

I finally sat down and spent a few minutes fixing my bash ‘exp’ alias a bit.

exp() {
# Grab the dir argument and put it in a friendly container
theDir=$1
# Only drop the volume if it exists otherwise /c* is ambiguous
if [[ "$theDir" == /c/* ]]; then
theDir=${theDir#/c}
fi
# Normalize '/' to '\' for Windows
theDir=${theDir//\//\\}
# Call explorer.exe with the swotted argument
/c/Windows/system32/explorer $theDir
}

Now I can use bash to launch Windows Explorer with an arbitrary directory without having to remember to swap out my path separators. It also means I can use tab-complete instead of having to type the entire path when jumping around the filesystem tree.

Yay!

[1] http://www.hanselman.com/blog/Console2ABetterWindowsCommandPrompt.aspx
[2] http://git-scm.com/downloads

Bitchin’

You know what really rocks on Windows? Git’s bash shell [1] wrapped with Console2 [2].

Git [3]: Come for the awesome revision control, stay for the bonus command shell.

I know I’ve nattered on about Console2 before [4] but that was just window dressing. Having an honest-to-goodness bash shell on a windows platform is real nice.

[1] https://openhatch.org/missions/windows-setup/install-git-bash
[2] http://www.hanselman.com/blog/Console2ABetterWindowsCommandPrompt.aspx
[3] http://git-scm.com/
[4] http://www.blackfez.com/?s=console2

More cmd.exe help

So you’re in cmd.exe and you type ‘ls‘ expecting to get a directory listing. Instead cmd.exe gives you the finger. You give cmd.exe the finger back. Just then your boss walks by and sees you flipping off company property. Next thing you’re in her office having a discussion on appropriate workplace behavior. Having had enough of ‘The Man’ you flip off your boss.

Now you’re sitting at the bus stop waiting for the bus that will take about 90 minutes to get you home. Just about 7 minutes faster than if you walked. But it’s cold outside. No job, no car, no prospects. Life sucks. And then you learn that you could have been using DOSKEY to set up persistent aliases in cmd.exe.

Just one simple DOSKEY ls=dir later and it doesn’t matter which platform you’re on. Assuming you already set aliases in .bashrc for all of your bad cmd.exe habits that is.

Chin up, young squire! Now when you’re fired from your next job, at least it won’t be on cmd.exe’s account. You can thank me later.