//Tips tagged wget
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
I wrote a small script, I named it "tw" to update twitter from terminal:

#!/bin/bash
echo "Your message please..."
read MSG
echo $MSG > characters
echo "Message length"
wc -c characters
echo "Password please..."
read -s PW
wget --keep-session-cookies --http-user=your.email@address.here --http-password=$PW \
    --post-data="status=$MSG" \
    http://twitter.com:80/statuses/update.xml
echo "Message posted."

This can also be used to update identi.ca (the open twitter alternative) by replacing the twitter url with 'http://identi.ca/api/statuses/update.xml'.


View Comments »



Use this command to backup your del.icio.us bookmarks from the commandline with curl.

curl -u username -o bookmarks.xml https://api.del.icio.us/v1/posts/all

Or, using wget

wget --user=username --password=password https://api.del.icio.us/v1/posts/all -O bookmarks.xml


View Comments »

Displays a random xkcd comic. Requires ImageMagick.

wget http://dynamic.xkcd.com/comic/random/ -O -| grep <img src="http://imgs.xkcd.com/comics | 
 sed s/<img src="// | sed s/"[a-z]*.*// | wget -i - -O -| display


View Comments »

When I read the tip yesterday (Twitter from the terminal), I thought it would be fun to set something up to tweet all the commands I enter. After a bit of playing around I have come up with the following:

First you'll need to create a script, it doesn't matter what you call it, just remember the name and path to it for later.

#!/bin/bash
read MSG
echo $MSG > characters
length=$(wc -c characters | sed 's/^[^0-9]*\([0-9]*\)[^0-9]*$/\1/')
if [ $length -le 140 ]; then
  wget -q --keep-session-cookies --http-user=YOURUSER --http-password=YOURPASS \
    --post-data="status=$MSG" \
    https://twitter.com/statuses/update.xml;
fi

You'll need to replace YOURUSER and YOURPASS as appropriate, and if you prefer to use identi.ca then change the twitter url to https://identi.ca/api/statuses/update.xml

Next run the following command, changing details at the end for the script you just created (note this does require you to use bash):

export PROMPT_COMMAND='echo "$(history 1)" | sed "s/^ *[0-9]* *//" | /path/to/script.sh'


Now every command you type will be sent to twitter! To turn this off, just run "export PROMPT_COMMAND=''" or logoff. Of course this isn't really a good idea to do all the time, though it is fun! Also remember that Twitter will block accounts that post over 100 updates per hour.

An example of the results can be seen here: https://twitter.com/ShellStream


View Comments »

The script below can be used to convert between different currencies on the command line. In order to use the script, you would enter something like "[scriptname] 150 USD GBP" to give the value of 150 US dollars in British pounds.

Supported currencies are Euro, U.S. dollar British pound, Japanese yen, Swiss franc, Canadian dollar, Australian dollar, and Indian rupee.

#!/bin/bash

toUpper() { echo $@ | tr "[:lower:]" "[:upper:]"; }

if [ $# -eq 2 ]
then
  NUM=1;CURRENCY1=$(toUpper "$1"); CURRENCY2=$(toUpper "$2")
elif [ $# -eq 3 ]
then
  NUM=$1;CURRENCY1=$(toUpper "$2"); CURRENCY2=$(toUpper "$3")
else
  echo "Usage: $0 [number] currency1 currency2"
  echo "Ex: $0 100 EUR USD"
  echo "Available currencies: EUR, USD, GBP, JPY, CHF, CAD, AUD, INR"
  exit 1
fi

CONVERSION=`wget -nv -O - "http://finance.google.com/finance?q=$CURRENCY1$CURRENCY2" 2>&1 | \
        grep "&nbsp;1&nbsp;$CURRENCY1&nbsp;" | \
        sed -e "s/^.*<span class=bld>&nbsp;\(.*\)&nbsp;$CURRENCY2.*$/\1/"`

if [ ${CONVERSION:-1} == "1" ]
then
  echo "Network error"
else
  RESULT=$(echo $CONVERSION \* $NUM | bc)
  echo "$NUM $CURRENCY1 = $RESULT $CURRENCY2"
fi

exit 0


View Comments »




Home Latest Browse Top 25 Random Hall Of Fame Contact Submit