Chapter 25. System Administration
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 needed only 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 7.12. Recipes 25.5, 25.6, 25.7, 25.8, and 25.9 all give different twists on this technique.
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 25.10 to look up a user’s ID given his username. Recipe 25.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 ...
Get Ruby Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.