Ghostscript check, sends e-mail if one occurs I've created a program that will search our work server where Ghostscripts occur. How it accomplishes this is by first sshing to the server specified, running a bash command to search the server for Ghostscripts caused by our guy that uses them, most frequently. If it finds one, it e-mails somebody on my team. It will also e-mail if it doesn't find one.

I'm curious to know if there are other ways I can do this specific task. Better syntax, etc..

#!/local/usr/bin/ruby

require 'rubygems'
require '&lt;mailgem&gt;'
require 'etc'
require 'net/ssh'

class GhostScript

  attr_accessor :host, :usr, :pass

  def initialize(host, usr, pass)
    @host = host
    @usr  = usr
    @pass = pass
  end

  def script_search
    ssh = Net::SSH.start(host, usr, :password =&gt; pass)
    res = ssh.exec!('ps -u &lt;user&gt;|grep gs')
    if res == nil
      MailGem::Mail.new do |m|
        m.to      = '&lt;email-address&gt;'
        m.subject = 'GhostScript not found'
        m.body    = "GS not found on server: #{host}"
      end.send
      else
      alert(res)
    end
  end

  def alert(res)
    MailGem::Mail.new do |m|
      m.to      = '&lt;email-address&gt;'
      m.subject = 'GhostScript found'
      m.body    = "GS script found on server: #{host}",
                  "Results of search: #{res}"
    end.send
  end
end

check = GhostScript.new('&lt;server&gt;', Etc.getlogin, nil)
check.script_search
Looks pretty good, just some minor details:


if res == nil -> if !res
DRY the sending of the email by creating a new method: send_email(to, subject, body)
Subjective: I'd not include a blank lines when there is a change of indentation level (between class and attr_accesor)