Skip to content

Instantly share code, notes, and snippets.

@twoism
Last active December 11, 2015 14:48
Show Gist options
  • Save twoism/4616300 to your computer and use it in GitHub Desktop.
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.
#!/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."
})
@laserlemon
Copy link

Sounds like a job for Dead Man's Snitch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment