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

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:  16.03.2020
#   version:   0.3
# -----------------------------------------------------------------------------
# Requirements:
#   curl, jq
# Description:
#   Simple Shell script to Shorten your Long URL via Bitly API V4.
# -----------------------------------------------------------------------------

# Bitly Generic access token
Accesstoken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
api=https://api-ssl.bitly.com/v4/shorten

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 -H Authorization:\ $Accesstoken -H Content-Type: -d '{"long_url": "'"$longurl"\"} $api | jq -j .link | xsel -ib; xsel -ob; echo

  • Find this # Bitly Generic access token line & Enter your Bitly account Generic access token
  • Run this below command line to execute the script
chmod a+x short.sh
./short.sh

Bitly URL Shortener Using Shell script

Official Bitly API Docs - https://dev.bitly.com/v4/

Related Topics