Here is the Simple Shell Script which Helps us to Shorten our Login URL into Short URL via Bitly API v3.

Requirements

  • cURL
  • jq ( sudo apt install jq )
  • Bitly Generic access token

Get Bitly Generic access token

Setup

  • Create a New bash file & Named as short.sh
  • open short.sh
  • copy & paste this below shell script on the bash file (short.sh) & save it

#!/usr/bin/env bash

# -----------------------------------------------------------------------------
# Info:
#   author:    Santhosh veer
#   file:      short.sh
#   created:   29.01.2018
#   revision:  19.02.2018
#   version:   0.2
# -----------------------------------------------------------------------------
# Requirements:
#   curl, jq
# Description:
#   Simple Shell script to Shorten your Long URL via Bitly API V3.
# -----------------------------------------------------------------------------

# Bitly Generic access token & Username
Accesstoken="your Generic access token"
username="Bitly account username"

echo -n "Enter your Long URL: "
read -r longurl

echo "[+] URL Shortening Started..."

  # If no URL you will see this Alert message
  if [[ ! $longurl ]]; then
    echo -e "Error URL Missing"
    exit 1
  fi

# Curl request
curl -s --request GET \
    --url "https://api-ssl.bitly.com/v3/shorten?access_token=$Accesstoken&login=$username&longUrl=$longurl" \ | jq
    
  • Find this # Bitly Generic access token & Username line & Enter your Bitly account Generic access token & username
  • Run this below command line to execute the script
bash short.sh

Bitly URL Shortener Using Shell script

Official Bitly API Docs - http://dev.bitly.com/links.html

Related Topics