Posted By

mvrilo on 06/07/10


Tagged

url Shell Bash google script shortener googl


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

scottshane


Google URL shortener script


 / Published in: Bash
 

URL: http://gist.github.com/346451

  1. #!/bin/bash
  2. # Google url shortener bash script
  3. # For information about the app:
  4. # http://ggl-shortener.appspot.com/instructions/
  5.  
  6. app='http://ggl-shortener.appspot.com/?url='
  7. url="$1"
  8. protocol=`echo "$1" | sed -e "/^http:\/\//g"`
  9.  
  10. if [ -z "$1" ]; then
  11. echo -e "you need to pass the url through an argument";
  12. echo -e "e.g. `basename $0` http://url";
  13. else
  14. if [ ! "$protocol" ]; then
  15. curl -s "$app$url" | sed -e 's/{"short_url":"//' -e 's/"}/\n/g'
  16. else
  17. repl=`echo "$1" | sed -e 's/^/http:\/\//g'`
  18. curl -s "$app$repl" | sed -e 's/{"short_url":"//' -e 's/{"error_message":"Bad request/error: bad request/' -e 's/"}/\n/g'
  19. fi;
  20. fi

Report this snippet  

You need to login to post a comment.