5 Replies - 2031 Views - Last Post: 21 December 2009 - 09:04 AM Rate Topic: -----

#1 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 243
  • Joined: 29-November 08

Simple Bash Script to post to twitter

Posted 11 December 2009 - 12:49 PM

Here is my code

#!/bin/bash
#
#Braber01
#12/11/2009
# Post a Status to Twitter without getting online

echo "What do you want to say to Twitter?"
read twitterStatus

if [ $twitterStatus = /.*\w{5,140}/ ]; then

curl -u "UserName":"Password" -d status="$twitterStatus" [url="http://twitter.com/statuses/update.xml"]http://twitter.com/statuses/update.xml[/url]

else

echo "Too many charcters in status, Limit is 140"
fi


This post has been edited by Braber01: 11 December 2009 - 12:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Simple Bash Script to post to twitter

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Simple Bash Script to post to twitter

Posted 11 December 2009 - 12:54 PM

Where are you having problems?
Was This Post Helpful? 0
  • +
  • -

#3 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 243
  • Joined: 29-November 08

Re: Simple Bash Script to post to twitter

Posted 11 December 2009 - 01:47 PM

View Postsnoj, on 11 Dec, 2009 - 11:54 AM, said:

Where are you having problems?

Sorry i totaly for got that in the if statement i'm having touble the regular expression when i test the script I'm getting an output saying "too many arguments on line 11"
Was This Post Helpful? 0
  • +
  • -

#4 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 243
  • Joined: 29-November 08

Re: Simple Bash Script to post to twitter

Posted 11 December 2009 - 01:56 PM

View PostBraber01, on 11 Dec, 2009 - 12:47 PM, said:

View Postsnoj, on 11 Dec, 2009 - 11:54 AM, said:

Where are you having problems?

Sorry i totaly for got that in the if statement i'm having touble the regular expression when i test the script I'm getting an output saying "too many arguments on line 11"

in this case it's line 8 where the if statement is
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Simple Bash Script to post to twitter

Posted 11 December 2009 - 03:39 PM

How about
if [ ${#twitterStatus} -lt 5 ]; then
	echo "Too few characters"
elif [ ${#twitterStatus} -gt 140 ]; then
	echo "Too many charcters in status, Limit is 140"
else
	echo "OK"
fi


Was This Post Helpful? 0
  • +
  • -

#6 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 243
  • Joined: 29-November 08

Re: Simple Bash Script to post to twitter

Posted 21 December 2009 - 09:04 AM

hey evrybody just thought i'd give you an update of the twitter shell that i'm working on...

#!/bin/bash
#Twitter.sh
#Using prompts

clear
echo "Login to Twitter..."
echo
echo "Twitter Username?"
read -p "twitter> " USER
echo
echo "Twitter Password?"
read -sp "twitter> " PASS

echo "Welcome to the twitter shell."
echo "What do you want to do?"
CMD=""
while [ "$CMD" != "bye" ];
do
read -p "twitter> " CMD
if [ "$CMD" == "show" ];then
echo "Enter a Twitter ID"
read -p "twitter> " ID
curl "http://twitter.com/statuses/show/${ID}.xml"
#do somthing with xmlstarlet here to make the xml into readable text for the #user
elif [ "$CMD" == "update" ]; then
echo "Update your status to ...?"
read -p "twitter> " STATUS
LEN=$(echo ${#STATUS})
if [ $LEN -le 140 ]; then
curl -u "$USER":"$PASS" -d status="$STATUS" http://twitter.com/statuses/update.xml > /dev/null
clear
echo "Status updated."
else
echo "Too many letters in stats."
fi
elif [ "$CMD" == "destory" ]; then
echo "Status ID?"
read -p "twitter> " ID
curl "http://twitter.com/statuses/destory/${ID}.xml
#Do somthing with xmlstarlet here
elif [ "$CMD" == "p_timeline" ]; then
curl http://twitter.com/statuses/public_timeline.rss
#xmlstarlet sel
elif [ "$CMD" == "rt" ]; then
echo "retweet wich status?"
read -p "twitter> " ID
curl http://api.twitter.com/1/statuses/retweet/${ID}.xml
#xmlstarlet sel
elif [ "$CMD" == "rts" ]; then
echo "the first 100 retweets of wich status?"
read -p "twitter> " ID
curl http://api.twitter.com/1/statuses/retweets/${ID}.xml
#xmlstarlet sel
elif [ "$CMD" == "help" ]; then
echo "show   returns a single status by a given id"
echo "p_timeline  show's the last 20 tweets of evrybody on twitter"
echo "update	 updates you status"
echo "destory	deletes a tweet by a given id"
echo "rt	 retweets a status by a given id"
echo "rts	 shows up to the first 100 retweets of a given tweet by id"
elif [ "$CMD" == "bye" ]; then
clear
else
echo "not an option"
fi
done


As you can see I'm trying to make this look and feel like a fully functional shell prompt any help with making the bash commands work via !command through this shell program would be greatly apprechatied rock on Linux users
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1