Ruby is a highly feature-rich, free, simple, extensible, portable, and object-oriented scripting language. It has gained immense popularity of late on the worldwide Web. This popularity can at least partly be attributed to the very powerful Web application development framework, Rails, which is written in Ruby. Rails, or Ruby on Rails ( ROR ), as it is called, provides a very powerful platform to very quickly and efficiently develop a Web application. It is highly scalable and there are many sites on the Web that have been built using Ruby on Rails..
Besides the use of Ruby with Rails as a Web application development platform, there is another less-heralded side to Ruby, which is Ruby as a powerful scripting language, much in the same league as Python or Perl. It has immense capabilities, owing to the availability of many built-in and external libraries, the power of which can be harnessed to solve a great deal of the scripting needs that might crop up in any work environment.
Systems administration is one such work environment that demands a lot of scripting for making things simpler and more efficient. User management, Process management, File Management, Software package management, and other basic automation requirements are better handled with scripting than with monotonous manual effort. Ruby comes in very handy in this scenario. It has a good set of libraries for achieving this.
In this article, I will start with examples showing how Ruby can be put to use for simplifying some of the basic scripting needs of systems administration. These examples introduce the capabilities of Ruby as a powerful alternative to shell scripting. The examples definitely provide room for a lot of improvement and can be further enhanced or customized as seen fit. After the basic examples, I will introduce a very powerful system administration library for Ruby called Cfruby. This library incorporates a wide set of functionality to make systems administration and management easier.
For this article, I assume that the reader has a working knowledge of Ruby. The basic examples that I present here use pure Ruby and hence should work on any UNIX®-like system supported by Ruby, as well as on Windows®. For the more advanced Cfruby examples, you will need access to a UNIX system. All the examples below have been tried with Ruby v1.8.4 on a Linux® box. They should work with the latest version of Ruby, as well.
Back to top
Ruby in action
The first example here searches for files that match the given pattern in the path specified and gives the detailed information of these files in a user-friendly manner. This doesn't depend on any command-line utility, but just uses Ruby's built-in APIs for achieving the objective. Hence, it will work on any platform where Ruby runs.
Also, it shows how powerful Ruby can be to greatly simplify such scripting requirements. Here, it does not just emulate the *nix "find" command, but builds upon it, thus showing the customizing power when using Ruby.
In this example:

