Created
July 15, 2020 19:30
-
-
Save rojenzaman/6d4ee4a8de5caddf570c48ec54778701 to your computer and use it in GitHub Desktop.
Static Url Shortener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ "$#" -lt 2 ]; then | |
| echo "./`basename $0` <write url here> <write your site directory here> [second] [\"title\"] [\"html code or txt\"]"; | |
| exit 1; | |
| fi | |
| url=$1 | |
| directory=$2 | |
| if [ "$#" -gt 1 ]; then | |
| second=$3 | |
| if [ -z "$second" ]; then | |
| second="0" | |
| fi | |
| title=$4 | |
| html=$5 | |
| fi | |
| cd $directory; | |
| random_url=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1); | |
| while [ -f "$directory/$random_url" ]; | |
| do | |
| random_url=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1); | |
| done | |
| mkdir $random_url && cd $random_url; | |
| cat > index.html << EOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="refresh" content="$second; url=$url" /> | |
| <title>$title</title> | |
| </head> | |
| <body> | |
| <h1>redirect to <a href="$url">$url</a></h1><br> | |
| $html | |
| </body> | |
| </html> | |
| EOF | |
| if [ -z "$title" ]; then title="null"; fi | |
| if [ -z "$html" ]; then html="null"; fi | |
| echo "url = $url" | |
| echo "site directory = $directory" | |
| echo "sleep time = $second" | |
| echo "title = $title" | |
| echo "html code = $html" | |
| echo "-------------------------------------------" | |
| echo "SHORT URL = http://yourhostname/$random_url" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Static Url Shortener
URL Shorter For Static Web Pages (written by bash shell programming language)
install:
git clone https://github.com/rojenzaman/static-url-shortener.git cd static-url-shortenerusage: