Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Forked from copiousfreetime/alert_me
Created November 22, 2009 22:14
Show Gist options
  • Save juliocesar/240756 to your computer and use it in GitHub Desktop.
Save juliocesar/240756 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
##
# alertme
#
# A simple delay timer to send a growl notification at specific time with a
# message. Useful for when you need to check on something later
#
# echo "Go look at system 42" | alertme in 2 hours
##
# If you're using rubygems, throw the line below in your shell init. E.g.: .bashrc for Bash
# export RUBYOPT=rubygems
# require 'rubygems'
require 'ruby-growl'
require 'chronic'
require 'daemons'
default = Chronic.parse "in 10 seconds"
alert = Chronic.parse(ARGV.join(" ")) || default
delay = alert - Time.now
message = STDIN.read
STDERR.puts "Unable to do an alert in the past" and exit 1 if alert < Time.now
STDERR.puts "You need a message" and exit 1 if message.empty?
APP = "alertme"
HOST = "localhost"
TITLE = "alertme Notification"
Daemons.daemonize
$0 = "alert at #{alert.strftime("%Y-%m-%d %H:%M:%S")}"
sleep delay
growl = Growl.new 'localhost', 'alertme', [TITLE], [TITLE], nil
growl.notify TITLE, TITLE, message, 1, true
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment