Created
September 27, 2010 20:29
-
-
Save jkap/599768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This requires the mail gem | |
# To use, run './notify.rb "<your command>"' | |
# make sure to set it as executable first using 'chmod +x notify.rb' | |
# email jbklego{at}gmail{dot}com with issues. | |
require 'rubygems' | |
require 'mail' | |
@command = '' | |
ARGV.each do|a| | |
if ARGV.count > 1 | |
puts "Error: Put your command in quotes, fool!" | |
exit 1 | |
end | |
if ARGV.count < 1 | |
puts "Error: You have to actually put something!" | |
exit 1 | |
end | |
@command = a | |
end | |
@output = `#{@command}` | |
puts @output | |
Mail.defaults do | |
delivery_method :smtp, { :address => "smtp.gmail.com", | |
:port => 587, | |
:domain => 'gmail.com', | |
:user_name => '<username>', | |
:password => '<password>', | |
:authentication => 'plain', | |
:enable_starttls_auto => true } | |
end | |
@body = 'Your job, "' + @command.to_s() + '", has just completed. | |
This is its output: | |
' + @output + ' | |
You may now proceed as usual.' | |
mail = Mail.new | |
mail.from = '<your email>' | |
mail.to = '<desired address>' | |
mail.subject = 'job complete' | |
mail.body = @body | |
mail.deliver! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment