Last active
December 11, 2015 14:48
-
-
Save twoism/4616300 to your computer and use it in GitHub Desktop.
Script to direct message a twitter account the exit status of any command.
This file contains 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 -W0 | |
# First install the twitter gem | |
# % gem install twitter | |
# | |
# Then install this script somewhere in your path | |
# and add the follwing to your bashrc or zshrc. | |
# | |
# export TWITTER_CONSUMER_KEY=<YOUR KEY> | |
# export TWITTER_CONSUMER_SECRET=<YOUR SECRET> | |
# export TWITTER_OAUTH_TOKEN=<YOUR TOKEN> | |
# export TWITTER_OAUTH_TOKEN_SECRET=<YOUR OAUTH SECRET> | |
# export TWITTER_DM_USER=<WHO GETS THE DM> | |
# | |
# Usage: | |
# % dmd [command] | |
# | |
# Example: | |
# % dmd sleep 2 | |
%w{rubygems twitter}.each {|l| require l} | |
command = ARGV.join(' ') | |
start_time = Time.now | |
puts `#{command}` | |
end_time = Time.now | |
total_time = "%05.2f" % (end_time - start_time) | |
status = $?.to_i > 0 ? 'failed' : 'succeeded' | |
Twitter::Client.new.post('/1/statuses/update.json', { | |
:status => "d #{ENV['TWITTER_DM_USER']} '#{command}' #{status} in #{total_time}s." | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sounds like a job for Dead Man's Snitch!