· 8 years ago · Jun 13, 2018, 04:02 AM
1#!/usr/bin/env ruby
2
3# This requires the mail gem
4# To use, run './notify.rb "<your command>"'
5# make sure to set it as executable first using 'chmod +x notify.rb'
6# email jbklego{at}gmail{dot}com with issues.
7
8require 'rubygems'
9require 'mail'
10
11@command = ''
12
13ARGV.each do|a|
14 if ARGV.count > 1
15 puts "Error: Put your command in quotes, fool!"
16 exit 1
17 end
18 if ARGV.count < 1
19 puts "Error: You have to actually put something!"
20 exit 1
21 end
22 @command = a
23end
24
25@output = `#{@command}`
26
27puts @output
28
29Mail.defaults do
30 delivery_method :smtp, { :address => "smtp.gmail.com",
31 :port => 587,
32 :domain => 'gmail.com',
33 :user_name => '<username>',
34 :password => '<password>',
35 :authentication => 'plain',
36 :enable_starttls_auto => true }
37end
38
39@body = 'Your job, "' + @command.to_s() + '", has just completed.
40This is its output:
41
42' + @output + '
43
44You may now proceed as usual.'
45
46mail = Mail.new
47mail.from = '<your email>'
48mail.to = '<desired address>'
49mail.subject = 'job complete'
50mail.body = @body
51
52mail.deliver!