Command-line Twitter with Bash
$ tweet "The sun is out and I am going to make a sandwich. #montreal #food" <span class="graphicSubtext"><a href="http://twitter.com/solutious/status/2620100947">Some minutes ago</a> from web</span>
I found a gist the other day by defunkt with a bash function for posting to Twitter from the command-line. It’s a cute hack but it was insecure so I updated it to work securely over HTTPS.
Step 1: Update ~/.bashrc
Step 2: Update ~/.netrc
Put your twitter credentials into ~/.netrc
. This file is read by curl.
# put this in ~/.netrc
machine twitter.com
login USERNAME
password PASSWORD
Then update the file permissions so only you can read it:
$ chmod 600 ~/.netrc
Step 3: Update SSL certs
$ source ~/.bashrc
$ updatecerts
This downloads a copy of the Mozilla SSL certificate authority bundle to ~/.cacerts.pem. curl uses this file to verify the SSL certificate for http://twitter.com/
Step 4: Tweet!
$ tweet "Anything at all"
Errors
Digest mismatch for $CERTS_FILE (maybe it was updated?)
This probably means that the Mozilla SSL certificate authority bundle has been updated. First check that the date in the bundle is later than “Thu Mar 26 2009”. If it is, then you need to do the following:
- Download the latest copy of the bundle by running
updatecerts
(ignore the error) - Update
CERTS_DIGEST
in~/.bashrc
with the output from:openssl sha1 $CERTS_FILE
If the date has not changed, the ~/.cacerts.pem
file has been modified. It may have been tampered with or corrupted. Delete it an run updatecerts
again.
Contributors
If I missed anyone, please let me know!