midaWeb/website-size.sh
2024-01-22 18:52:48 +01:00

53 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
output="./${!#}.log"
sites_output="./${!#}_sites.log"
mides_output="./${!#}_mides.log"
year=$(date +"%Y")
echo "Analitzant ${!#}..."
sleep 1s
echo "Pot tardar una estona..."
echo ""
wget \
--recursive --level=1 \
--spider --server-response \
--no-directories --no-parent \
-e robots=off \
--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"
echo ""
sleep 1s
grep -e "--$year" $output | awk '{printf("%s\n", $3)}' | sort | uniq >> $sites_output
sed -i '$ d' $sites_output
sed -i '1d' $sites_output
echo "## Resum dels fitxers baixats ##"
sleep 1s
while read line; do
wget --server-response --no-directories --spider -e robots=off --output-file="$mides_output" "$line"
echo "$line $(grep -e "Content-Length" $mides_output | awk '{printf("%.2fKb\n", $2 / 1024)}')"
rm $mides_output
done < $sites_output
#grep -e "Content-Length" $output | awk '{printf("%.2fKb\n", $2 / 1024)}' >> $mides_output
# echo "## Resum dels fitxers baixats ##"
# sleep 1s
#echo "$(paste $sites_output $mides_output | uniq)"
# Delete wget output file
rm "$output"
rm "$sites_output"
else
echo "Unable to calculate estimated size."
exit 1
fi
exit 0