create a twitter info server with bash

Upload: ikhwani-fill-ilmi

Post on 03-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Create a Twitter Info Server With Bash

    1/2

    Using Bash Shell Scripts for Twitter Updates and Information PostingThese scripts are used to both send tweets from the command line and to automateinformation to your Twitter account. You can use your Linux server or desktopto help present useful information to your account, not Spam. This creates a way to present tips, FAQ, and other information to people as they follow your account.Tweet MessageThe first example is a bash script that you can save in your home directory, saycall it twitter.sh and then chmod 755 the script. Here is how the script works. The two variables at the start, are where you will need to enter your email address and then your password. These variables are called later in the script.The URL variable is used to connect to the twitter account and is used later in the script. The result line uses curl to send the username and password to twitterto connect to the account and then the status message is what is tweeted on your account.#################################!/bin/bash# tweet_mess.sh Tweet from your Linux accountUSERNAME=email_or_usernamePASSWORD=passwordURL=http://twitter.com/statuses/update.xml# Post to Twitter.result=`curl -u $USERNAME:$PASSWORD -d status=This is where you will place your message for Twitter $URL`

    exit 0################################Tweet AliasThe second illustration is when you want to create an alias in your .bash_profile so that you can use a simple command and send text anytime from the command line. Open your .bash_profile, this is a hidden file in the users directory, and edit it and place this line to create an alias:alias twhome/user_name/tweet_com.shNow you will need to edit this file tweet_com.sh and place your username and password in it . You will not make any other modifications to the script, exceptto make sure it is executable.chmod 755 tweet_com.shMake sure your .bash_profile is ready with:

    cd ~source .bash_profileNow from the command line just do this:tw Send a message from the command line#################################!/bin/bash# tweet_com.sh Tweet from the command lineUSERNAME=email_or_usernamePASSWORD=passwordURL=http://twitter.com/statuses/update.xml# Post to Twitter.result=`curl -u $USERNAME:$PASSWORD -d status=$1? $URL`exit 0

    ################################Tweet ServerThe Tweet Server provides you a way to create a script that will provide information to your users throughout the day. Note I said information, not Spam. Thepurpose is to give people free information that they can collect and use. It also provides a way for people to understand what your business is about or what you are about then they are making decisions if they want to follow you. In thisexample, two files were created. First, you can use the tweet_com.sh script inthe above example and then send messages to that script. The second script reads a file which you will create that has one tweet per line. Wherever you place

  • 7/28/2019 Create a Twitter Info Server With Bash

    2/2

    your scripts make sure you have the path correct and the path to the file called tweetfile. The sleep 3600 make sure you only tweet one line per hour, adjust that to your needs.#################################!/bin/bash# tweet_com.sh Tweet from the command lineUSERNAME=email_or_usernamePASSWORD=passwordURL=http://twitter.com/statuses/update.xml# Post to Twitter.result=`curl -u $USERNAME:$PASSWORD -d status=$1? $URL`exit 0#################################################################!/bin/bash# tweet_server.sh Reads a file to send to the tweet_com.shFILE=tweetfilewhile read LINEdo/home/user_name/scripts/tweet_com.sh $LINEsleep 3600done < $FILEexit 0################################

    Tweet server OptionThe disadvantage of the Tweet Server using sleep 3600 is that the script is running continually and so the resources, though small are really not used correctly. It would be better to use a crontab to run the script whenever you need to and then close it down. Here is an option that will do just that. This option will read one line, tweet the line, then delete the line by using sed to delete the first line and saving it as a temporary file. Then the temporary file is moved to replace the old file. This way you will not repeat any tweets that you setup.#################################!/bin/bash# tweet_server.sh Reads deletes line and replaces fileFILE=tweetfile

    read LINE