A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
Post to Twitter
This is my first Shell script for public release. Twitter is blocked at my workplace so this script allows me to use cURL and the Twitter API to post from the shell of my server.
The script requires only one variable in the configuration which is your username. You are prompted for your password each time you run the script to tweet. If you have a url you would like to share, the script will connect to the is.gd API to shorten the URL. The script will then subtract the length of the shortened url from the 140 total, as well as the space required to retweet (RT @username) the message for a total length available for the tweet. If you go beyond this length, you will be notified how far over you’ve gone. The script then sends the tweet via cURL with your message followed by the shortened URL at the end.
Information
-
@name Post to Twitter @filename post_to_twitter.sh @description This script will post to your twitter account from a Linux shell. You will need to enter your username in the configuration section. You will be prompted for your password each time you run the script. @author Mark Stoecker @version 0.1
Installation:
- Click here to download this script
- You can also download this through your Linux shell with the command:
wget http://www.poundbangwhack.com/scripts_source/shell/post_to_twitter.sh.txt - Once downloaded, upload the file to the home directory of your server/computer and save it with a .sh extension:
mv ~/post_to_twitter.sh.txt ~/post_to_twitter.sh - Add execute permissions to the script with
chmod a+x ~/post_to_twitter.sh - Run the script with the command
~/post_to_twitter.sh
Configuration:
- Open the script in any text editor and edit the line
u=""by adding your Twitter username between the quotes.
Bugs:
- No known bugs at this time
To Do:
- Nothing to do at this time
As always, if you have comments or suggestions, please share them below and they may be included in future versions of the script.

