#!/bin/sh
# url: http://pank.org/scripts/
# description: get file size via http
# comment: csh bash
# platform: all
# dependency: curl

if [ -z $1 ] ; then
    echo Usage: $0 "{url}"
else
    SIZE=`curl -Is $1 | awk '/Content-Length:/ {print $NF}'`
    if [ -z $SIZE ] ; then
        LOCATION=`curl -Is $1 | awk '/Location:/ {print $2}'`
        SIZE=`curl -Is $LOCATION | awk '/Content-Length:/ {print $NF}'`
        if [ -z $SIZE ] ; then
            LOCATION=`curl -Is $LOCATION | awk '/Location:/ {print $2}'`
            SIZE=`curl -Is $LOCATION | awk '/Content-Length:/ {print $NF}'`
        fi
    fi
    echo $SIZE
fi