From 5b01175a64032290602b1c564cbaf8e28413e817 Mon Sep 17 00:00:00 2001 From: Xaloc Date: Wed, 17 Jan 2024 21:40:34 +0100 Subject: [PATCH] primer commit --- LICENSE | 5 +++++ README.md | 10 ++++++++++ website-size.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 website-size.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e86b3ef --- /dev/null +++ b/LICENSE @@ -0,0 +1,5 @@ +"THE NON-ALCOHOLIC-BEVERAGE-WARE LICENSE": + + wrote this. As long as you retain this notice you can +do whatever you want with this stuff. If we meet some day, and you think this +stuff is worth it, you can buy me a non-alcoholic beverage in return Xaloc diff --git a/README.md b/README.md new file mode 100644 index 0000000..7928bd6 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Estimar la mida d'una pàgina web +Aquest escript de bash utilitza wget, grep i awk per estimar la mida d'una pàgina web. El script agafa tot el que hi ha al primer nivell de la pàgina però no mira recursivament cap més nivell. + +Aquest escript ha estat fortament inspirat d'[aquest repositori](https://github.com/izkreny/website-size) + +## Utilització +1. Còpia o baixa el script +1. Dona-li permisos d'execució `chmod +x website-size.sh` +1. Executa'l amb la pàgina que vulguis utilitzar com a argument `./website-size.sh example.org` + diff --git a/website-size.sh b/website-size.sh new file mode 100755 index 0000000..8be7138 --- /dev/null +++ b/website-size.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +output="/tmp/website-size.out" +echo "Analitzant ${!#}..." +sleep 1s +echo "Pot tardar una estona..." + +wget \ + --recursive --level=1 \ + --spider --server-response \ + --no-directories --no-parent \ + --output-file="$output" "$@" + +sleep 1s +if [ -f "$output" ] +then + # Calculate and print estimated website size + echo "Mida estimada de ${!#}: $(\ + grep -e "Content-Length" "$output" | \ + awk '{sum+=$2} END {printf("%.0f", sum / 1024)}'\ + ) kb" + + # Delete wget output file + rm "$output" +else + echo "Unable to calculate estimated size." + exit 1 +fi + +exit 0