Scripting IT, one step at a time.
Learning to script as a SysAdmin is like learning to breathe properly for an athlete: Sure you can get along without it, but you’ll never be as good as someone that knows it (in case you were wondering, proper breathing is done in through the nose, out through the mouth, and from the diaphragm not the chest).
Learning to script will save you time and make your network run much smoother. You’ll wonder how you ever got along without it once you’ve experienced the benefits of being able to do 10 hours worth of work in 10 seconds through the power of a script.
The biggest hurdle that I encountered when learning to script was deciding which language to learn (I foolishly thought that I only needed to learn one, and then I’d be good). On the Windows side the house, the progression of scripting languages usually goes something like this:
First you learn batch scripting (called shell scripting in the *NIX world, and by some in the Windows world). Then when you start running into things you can’t do with shell scripting, you learn VBScript. With the recent introduction of PowerShell from Microsoft you can now progress to that as well when you find the things you can’t do with VBScript (which will likely take a while, as VBScript is pretty robust).
If I could give a SysAdmin just starting out in scripting only one piece of advice, it would be to forget that progression. It takes too long (took me about 4 years to go from Shell Scripting to PowerShell). Start with PowerShell.
You are going to find that there is a bit of a steep learning curve for PowerShell if you have never done any scripting but the payoff, I promise you, is well worth the headache. Don’t get me wrong, VBScript has been the scripting language of choice for the Windows SysAdmin since the introduction of WSH (Windows Script Host) with Windows 2000, and there are several distinct benefits of learning VBScript:
- There are thousands of VBScripts readily available on the internet.
- Learning to work with WMI and ADSI in VBScript will teach you a lot about both.
- Pretty much anything you will want to do, someone has already done, and you can find their work via google (LAOAE applies here).
The reason I suggest that you go straight for PowerShell is the sheer power and flexibility that it offers. Unlike VBScript or shell scripting, PowerShell sees everything as an object, and as such gives you access to all of the DotNET Classes, Methods, and Properties for that object. This is very powerful when it comes to manipulating things with a script.
Another great reason to start off with PowerShell is that it was designed from the start to have built in security. By default PowerShell will not run scripts at all. Whereas the WSH (what runs VBScript) has no such compunctions, and will run ANY script right out of the gate (anybody remember the “I love you” virus?). In the past this has been an issue for SysAdmins, many going so far as to delete the WSH interpreter from their machines, so that NO scripts could be run.
On the Linux side the progression is from Shell Scripting, to Perl or Python. I would advise you to learn Shell Scripting first, as the BASH shell (the default on most Linux distros) is quite robust. Perl or Python (one is just as good as the other, though I prefer Python) will allow you to greatly expand what can be done with Shell Scripting. In addition, both Perl and Python can be run on Windows through the WSH interpreter.
At the end of the day making the commitment, and taking the time to learn a scripting language is more important than which language you choose. It will make your job easier, and make you feel like a Rock Star when you can use scripting to provide solutions to many of the difficulties you will face as a SysAdmin.
Graffiti: a societal blight, and how it can be dangerous to IT.
Graffiti is one of those things that I see so often I am pretty much inured to it. It disgusts me that our society has let it become such a pervasive blight in most cities that no one really cares about it anymore.
Personally I think the punishment for graffiti should be to have whatever garbage you were painting or writing branded on your face (if they only hold the brand for 2 seconds the resulting mark will only last for about 10 years, five seconds is good for a lifetime). But that’s just me.
The area of town where my office is located is rife with graffiti (yeah I work in the “hood”), and on most days there is a police department graffiti unit somewhere in the neighborhood (got a bit of a gang problem in that area as well). I see so much of the crap that I tend not to really notice it much.
Until this morning as I was kind of wandering aimlessly around our parking lot on my cell phone. Among the other random (I can’t read that crap) squiggles interspersed around the lot I found something different.
Here is a drawing of what I found (it was silver marker on gray concrete so I couldn’t get it to show up right on the camera I keep at the office):
At first I thought it was just kind of interesting, and then the realization of what I was looking at hit me: it’s not graffiti, it’s modified warchalking.
Warchalking has pretty much died out, so I’m not too sure about how many people even know what it is, but if you don’t, you need to read up on it. Let’s examine this image:
1. This is the warchalking symbol for a closed node. I know this because…
2. This is (or rather was) the SSID for the wireless access setup in the building that the symbol was in front of.
3. This is an interesting modification. I believe that the symbol in the small circle is noting that the signal is 802.11g, and the key shape is denoting that the node is password protected.
4. Traditionally the warchalking symbol will have a “W” in it if the node is WEP protected, I can only assume that this is a modification of that to show that the network is WPA2 encrypted.
After realizing this I was both furious and amused, as we apparently have a hood denizen that is both a petty criminal (hence the vandalism), and also believes he is some sort of computer criminal. I know that nothing was compromised, but I changed all of my wireless settings just in case.
I also contacted the graffiti abatement unit at the police station and explained what I had in the parking lot. They sent an investigator out to photograph the graffiti, and I explained to him what it meant, and he took notes. Hopefully when they catch the little punk they’ll confiscate his laptop and charge him with some cyber terrorism related crime.
The lesson I’ve learned is this – keeping an eye on the external environment can be an important bit of security.
Admin’s Arsenal: BareGrep.exe
Ok, here is the situation: you’ve got 1200 script files in a particular directory on your XP workstation, and you need to find any script that references “\\atl01\share” (queue Dennis Hopper voice), what do you do?!
Traditional convention is that you spend several hours opening each file in notepad and doing a “find”, or you might be able to cut it down to an hour or so if you opened several dozen of the files at a time in Notepad++ and did “find in all files”, or you could take about a half an hour and move the files over to a *NIX machine and use grep. I’ve got a better answer: BareGrep.exe from our friends at Bare Metal Software. BareGrep is basically a GUI version of the *NIX grep command for Windows machines, and it works wonderfully. Much like BareTail (which I reviewed here), BareGrep is fully portable, meaning you can run it from a USB drive! Here is a shot of the interface:
Here is a short list of some of the features in BareGrep:
- Regular expression text search (that’s inside the files)
- Wildcard and regular expression file search
- Files to find or search can be specified with a regular expression
- Multiple files can also be specified with the mouse
- Recursive directory search
- Frequently used text search patterns may be saved, named and edited
- Searching while you type, to find results quicker
- Capturing groups (using bracket characters ‘(‘ and ‘)’ in a regex) extract strings from files
- Tabular presentation of search results
- Export/copy of search results in many formats
- Search files of any size (> 2GB)
Not only will this utility do all that, but it is usable from the commandline as well! What more could you want? Wait, what? You want… more features? Well you’re in luck, as BareGrep comes in two forms, the Free version (what we’ve covered so far), and the Registered version ($25 at the time of this review), which offers all of the features of the free version, as well as:
- Selecting a search result line shows that line in context in the file
- Tabs display files recently viewed
- Tabs may be positioned on any side of the window and oriented horizontally or vertically
- Lines containing particular strings can be highlighted to help you notice important text
- Highlight colours are fully customizable
Now I can’t even begin to cover the colossal amount of time that this utility has saved me, but I can tell you that it is well worth the price of admission. BareGrep can be downloaded here.
-
Archives
- December 2008 (1)
- November 2008 (14)
- October 2008 (2)
- September 2008 (2)
- August 2008 (8)
- March 2007 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS


