Once you start using Ruby, you’ll want to use it everywhere. Well, nothing’s stopping you. This chapter shows you how to use Ruby in command-line programs that solve general everyday problems. It also demonstrates patterns that you can use to solve your own, more specific everyday problems.
System administration scripts are usually private scripts, disposable or lightly reusable. Ruby scripts are easy to write, so you can get the job done quickly and move on. You won’t feel bad if your script is less rigorous than your usual work, and you won’t feel invested in a huge program that you only needed once.
Ruby’s syntax makes it easy to write, but for system administration,
it’s the libraries that make Ruby powerful. Most of the recipes in this
chapter combine ideas from recipes elsewhere in the book to solve a
real-world problem. The most commonly used idea is the
Find.find technique first covered in Recipe 6.12. Recipes 23.5, 23.6, 23.7, 23.8, and 23.9 all give different twists on
The major new feature introduced in this chapter is Ruby’s standard
etc library. It lets you query a Unix
system’s users and groups. It’s used in Recipe 23.10 to look up a user’s
ID given their username. Recipe
23.9 uses it to find a user’s home directory and to get the members
of Unix groups.
Although these recipes focus mainly on Unix system administration, Ruby is perhaps even more useful for Windows administration. Unix has a wide variety of standard shell ...