It’s the Law

Ritter’s first law of network administration: An administrator at rest tends to stay at rest.

An administrator’s day could easily be consumed with all the little, mundane tasks that are necessary to keep things running smoothly. Backing up servers, reading log files, preparing reports on resource utilization, playing RuneScape—it all really eats into one’s time. That’s why I formulated my first law of network administration. I noted that, as a network admin, when things could pretty much take care of themselves, I could relax and better savor the more fulfilling moments of my job, like reducing a user’s disk quota or reading a user’s more provocative email messages. Here is a short, alliterative list of tips to help you achieve network nirvana:

Aggregate

Locate shared resources that have common security requirements in the same directory structure on your file server. Set access permissions only once on the highest-level directory that these files have in common. Use permission inheritance to ensure consistent security on all the files in the hierarchy.

Don’t assign permissions directly to users. Add users to appropriate groups and assign permissions to the groups. That way, you need only add a user to a group to ensure that all the access they require is properly configured.

Automate

Do nothing by hand if possible, because hands can be so error-prone sometimes. Learn a scripting language and write (or download and customize) scripts to perform common, repetitive tasks like reading log files and collecting report data. If you administer a windows network, you must learn PowerShell. It’s available for windows versions from XP onward, and is the “wave of the future.” If you administer a Linux network, you must learn bash. If you manage a mixed environment, I strongly recommend that you learn Python—it’s sufficiently platform-independent and very mature, with a smörgåsbord of cool features built in.

Alert

Let your network tell you when there are problems. Install a network monitor system that’s capable of notifying you when your file and email servers run low on disk space, or when your web server stops responding. When you can address an issue before your users even know it’s there, they’ll come to respect your precognitive powers and revere you for the system superhero you really are.

Well, that last one, not really, because they won’t know there was a problem in the first place, right? But hey, we’re geeks: we’re good at fantasy. Now roll a D20 to see whether your invisibility-from-Lumbergh spell worked before he asks for those TPS reports. Again.

Be seeing you.

Let x = a whole bunch of things

Set multiple variables at once in PowerShell

A list of variable names can be an l-value, that is, an expression that appears on the left side of an assignment operator. Did you know that you can do this…

PS C:\> $FirstName, $Initial, $LastName = 'John', 'Q', 'Public'

This statement will assign to each variable the corresponding value on the right of the assignment operator. What if the number of variable names and the number of values doesn’t match? Extra values will be stored as an array in the last variable.

PS C:\> $FirstName, $Initial, $LastName = 'John', 'Q', 'Public', 'Sr', 'Esq'

That $LastName variable will be a list containing Public, Sr, and Esq. If there aren’t enough values to go around, the extra variables are unassigned.

Oh, and if you want to set several variable names to the same value, use this:

PS C:\> $a = $b = $c = $d = 90

Have fun with your variables.

Be seeing you.

The Baker Street Regulars

The Basics of Regular Expressions

Introduction

Unix administrators have long used regular expressions to help them locate files, modify data, and manage system configurations. Tools like grep and sed are designed to process regular expressions to provide the administrator with exactly the information he wants. While versions of these tools have been ported to Windows, most Windows administrators are unaware that they exist. Because of the limitations of the Windows command shell, Windows administrators typically stick with slower, more complicated graphical tools to manage the operating system.

Enter PowerShell. PowerShell is designed to be a replacement for the standard Windows shell, and it is far more powerful and flexible than its predecessor. Among the many command enhancements PowerShell offers is built-in support for regular expressions. It borrows this capability heavily from Perl, a scripting language that was developed specifically for processing text.

Regular expressions are used to search for character sequences inside text strings or files. Programs that process regular expressions look for text that matches a given pattern. The components of a regular expression are not complicated, but the available combinations are many and varied, making it possible to perform some very sophisticated matches. Whether you’re administering Windows, Linux, or the Unix-based macOS, you should invest some time learning the cryptic syntax of regular expressions so that you can manage systems and automate common tasks.

This tutorial will introduce regular expressions. It is not aimed at a particular operating system. Students of both Linux and PowerShell will come away with a basic knowledge of how regular expressions work and how to craft their own. Specific tools such as Linux’s grep command and PowerShell’s -match operator are covered in those respective classes at Centriq Training.

Continue reading