summaryrefslogtreecommitdiff
path: root/head.bash
diff options
context:
space:
mode:
Diffstat (limited to 'head.bash')
-rwxr-xr-xhead.bash39
1 files changed, 39 insertions, 0 deletions
diff --git a/head.bash b/head.bash
new file mode 100755
index 0000000..df4cea7
--- /dev/null
+++ b/head.bash
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+read url
+arg1=`echo "$url" | cut -d\ -f1`
+argrest=`echo "$url" | cut -d\ -f1 --complement`
+
+if [[ $arg1 = "--version" ]]
+then
+ echo "Blatech head v0.2"
+ exit
+elif [[ $arg1 = "-h" || $arg1 = "--help" ]]
+then
+ echo "Give an HTTP URL to get its MIME type, size and modified date. -v for verbose output, --help for this help message, --version for the version number."
+ exit
+elif [[ $arg1 = "-v" ]]
+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`
+length=`grep Content-Length head.txt | cut -d " " -f2 | ./filesize.sh | sed -r "s/[ \t]{2,}//"`
+
+if [[ ! "$http" =~ "200" ]]
+then
+ echo $http
+else
+ if [ -z "$length" ] && [ -z "$modified" ]
+ then
+ echo "$type"
+ else
+ echo "$type | $length | $modified"
+ fi
+fi