#!/bin/bash function filesize { echo $1 | awk 'function human(x) { s=" B KiB MiB GiB TiB EiB PiB YiB ZiB" while (x>=1024 && length(s)>1) {x/=1024; s=substr(s,5)} s=substr(s,1,4) xf=(s==" B ")?"%5d ":"%8.2f" return sprintf( xf"%s\n", x, s) } {gsub(/^[0-9]+/, human($1)); print}' } read url arg1=`echo "$url" | cut -d\ -f1` argrest=`echo "$url" | cut -d\ -f1 --complement` if [[ $arg1 = "--version" ]] then echo "Blatech head v0.3" exit elif [[ $arg1 = "-h" || $arg1 = "--help" ]] then echo "Give an HTTP URL to get its MIME type, size and modified date. --vebose or -v for verbose output, --help or -h for this help message, --version for the version number." exit elif [[ $arg1 = "-v" || $arg1 = "--verbose" ]] then curl -sI "$argrest" | sed ':a;N;$!ba;s/\r\n/ | /g' | sed 's/ | \r$//' exit fi curl -sI "$url" > head.txt sed -i ':a;N;$!ba;s/\r//g' head.txt http=`grep HTTP head.txt` modified=`grep Last-Modified head.txt | sed "s/Last-Modified: //"` type=`grep Content-Type head.txt | cut -d " " -f2` location=`grep Location head.txt | cut -d " " -f2` length=`grep Content-Length head.txt | cut -d " " -f2` length=`filesize $length | sed -r "s/[ \t]{2,}//"` if [[ "$http" =~ "301" || "$http" =~ "302" ]] then echo "$http to $location" elif [[ ! "$http" =~ "200" ]] then echo $http else if [ -z "$length" ] && [ -z "$modified" ] then echo "$type" else echo "$type | $length | $modified" fi fi rm head.txt