This is a neat trick. A friend was looking for a convenient way to tweet (or send to statusnet) from Bash, this is a fairly straightforward way to do that.
There are a couple of bits you need before we play with the script. You’ll need cURL installed, many Unices do this by default, but an apt-get install curl will probably work. You’ll need oauth_sign to allow you to sign in to the API. Finally you need to get an access token set up in the twitter API bit.
You can get your API details by logging in to the Twitter dev bit. Go to my applications (which is in the dropdown at the top right that has your profile pic on it). Create a new application and create your access token. You have to make it read/write rather than the default of read only.
Next grab bashtweet.sh — I put it in a directory. You’ll need to paste in the oauth details you created in the last paragraph in the appropriate places.
$ cd bashtweet
$ wget http://charlieharvey.org.uk/writings/bashtweet.sh
Finally you have to get and compile oauth_sign.
$ wget http://acme.com/software/oauth_sign/oauth_sign_09jan2012.tar.gz
--2013-05-01 18:28:20-- http://acme.com/software/oauth_sign/oauth_sign_09jan2012.tar.gz
Resolving acme.com... 126.96.36.199
Connecting to acme.com|188.8.131.52|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8086 (7.9K) [application/x-tar]
Saving to: `oauth_sign_09jan2012.tar.gz'
100%[==================================================================================================================================================================================================>] 8,086 8.14K/s in 1.0s
2013-05-01 18:28:21 (8.14 KB/s) - `oauth_sign_09jan2012.tar.gz' saved [8086/8086]
$ tar xvzf oauth_sign_09jan2012.tar.gz
$ cd oauth_sign/
gcc -c -Wall -O liboauthsign.c
liboauthsign.c: In function â€˜oauth_signâ€™:
liboauthsign.c:123: warning: implicit declaration of function â€˜getpidâ€™
liboauthsign.c:305: warning: pointer targets in passing argument 4 of â€˜HMACâ€™ differ in signedness
/usr/include/openssl/hmac.h:99: note: expected â€˜const unsigned char *â€™ but argument is of type â€˜char *â€™
rm -f liboauthsign.a
ar rc liboauthsign.a liboauthsign.o
gcc -Wall -O oauth_sign.c -L. -loauthsign -lcrypto -o oauth_sign
Assuming that everything went to plan you should now be able to tweet from your terminal!
$ ./bashtweet.sh Beautiful Mayday. Time for a beer
[Lots more JSON removed]