How to send tweets at random times with a *NIX CLI …

Twitter CLI is a wonderful tool for automatically sending tweets. Very simply, after installation, you just need to run ‘t update “message”‘ and it would tweet your message. I wanted to do some tweeting randomly via cron, but since cron runs regularly at an interval, it’s not very random. Just adding a couple of lines to the script will make it random.

Here’s how to do it.

First, download and install Twitter CLI from here: https://github.com/sferik/t

Afterwards, make a copy of the t script and call it what you want. I call it randomt:

cp /usr/local/bin/t /usr/local/bin/randomt

Finally, just make a change to the script. Here, I’m setting a variable called time and making it a random number between 1 and 1000. From there, I’m multiplying it by 60 to convert it to minutes.

#!/usr/bin/ruby2.0
#
# This file was generated by RubyGems.
#
# The application 't' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

time = 1 + rand(1000) * 60
sleep(time)

if ARGV.first
 str = ARGV.first
 str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
 if str =~ /\A_(.*)_\z/
 version = $1
 ARGV.shift
 end
end

gem 't', version
load Gem.bin_path('t', 't', version)

Now, my tweets go out at some random time between 1 and 1000 minutes later. Thanks for reading!

 

 

Leave a Reply