Scripting in Ruby

I just read, or rather skimmed, the book, called Everyday Scripting with Ruby and it is awful. I had high expectations. I was expecting something like
Perl for System Administration, where you right away get into hard core Perl scripting. This book is nothing like that! It is a really basic introduction to Ruby, and if you have any experience programming at all, DON’T BUY THIS BOOK.

OK, enough complaining! I am going to do what this book does not do. I am going to show a good way to write scripts in Ruby. If you want to learn more about Ruby, buy
Programming Ruby, The Well-Grounded Rubyist and The Ruby Way.

Ruby is an excellent language. It is, in my opinion, the best scripting language and it beats both Perl and Python face down. If you are not scripting in Ruby, you are missing out.
Ok, so here is the script.


The script is called sendgmail and it sends mail via gmail (surprise!).

This is how the command is used.

And here is the code, liberally sprinkled with comments.

Install required dependencies on OS X

The script requires you to install sendemail.

It also requires you to install Growl. The latest version 2.0 can be bought from the Mac App Store. The growlnotify command line utility can be downloaded fromGrowl Downloads. The gem that uses this utility, also conveniently named growl can be installed as normal gems.

That’s it, a simple script that will allow you to send messages and files through
gmail from the command line.

This Post Has 4 Comments

  1. Awesome. This script is a great application. Ruby it’s fantastic. Thanks!

  2. This is what I’ve looked for!!!! Thank you very much!

  3. This worked great, thank you. A few notes to add…

    1.) A space needs to be added to the concatenation so the two lines are separated by a space.
    2.) For those who aren’t using port, you can simply download the tar.gz from and place the perl script in your PATH.
    3.) I opted to use port 587 because port 25 is blocked by many ISPs.

    Gist with updates:

  4. Jason, thanks for the feedback. I’m glad you liked it.
    I will update as per your suggestions.

Leave a Reply

Close Menu