Advertisement
voyeg3r

short

Aug 21st, 2019
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.52 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # -----------------------------------------------------------------------------
  4. #       author:  Santhosh veer
  5. #         file:  short
  6. #  Last Change:  ago 21 2019 14:26
  7. # -----------------------------------------------------------------------------
  8. # Requirements: curl, jq, xclip
  9. # Description: Simple Shell script to Shorten your Long URL via Bitly API V3.
  10. # -----------------------------------------------------------------------------
  11.  
  12. # Reference: https://unix.stackexchange.com/questions/69111/
  13. # Source: https://itrendbuzz.com/bitly-url-shortener-using-shell-script/
  14. # Get Bitly Generic access token
  15. # Log in to your Bitly account
  16. # Open this Link- https://bitly.com/a/oauth_apps & get your Generic access token
  17.  
  18. # Bitly Generic access token & Username
  19. # In my case I have protected my token in a file that I have permissions to read
  20. Accesstoken=$(cat ~/.config/bitly-token)
  21. username="voyeg3r"
  22.  
  23. # echo -n "Enter your Long URL: "
  24. # read -r longurl
  25.  
  26. # echo "[+] URL Shortening Started..."
  27.  
  28.   # If no URL you will see this Alert message
  29.   if [[ ! ${1} ]]; then
  30.     echo -e "Error URL Missing"
  31.     exit 1
  32.   fi
  33.  
  34. # Curl request
  35. # curl -s --request GET \
  36. #     --url "https://api-ssl.bitly.com/v3/shorten?access_token=$Accesstoken&login=$username&longUrl=${1}" \ | jq
  37.  
  38. # Curl request
  39. curl -s --request GET \
  40.     --url "https://api-ssl.bitly.com/v3/shorten?access_token=$Accesstoken&login=$username&longUrl=${1}" \ | jq \ |
  41.     awk -F'"' '/"url":/ {print $4}' | tee >(xclip -i -selection clipboard)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement