diff options
-rwxr-xr-x | head.bash | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -1,5 +1,17 @@ #!/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` @@ -24,7 +36,8 @@ 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` -length=`grep Content-Length head.txt | cut -d " " -f2 | ./filesize.sh | sed -r "s/[ \t]{2,}//"` +length=`grep Content-Length head.txt | cut -d " " -f2` +length=`filesize $length | sed -r "s/[ \t]{2,}//"` if [[ ! "$http" =~ "200" ]] then |