Files
control-rss/control-rss.sh
2026-01-13 10:11:05 -05:00

45 lines
1.6 KiB
Bash

#!/bin/bash
# Cargar configuración
source config.conf
# Creacion del JSON si no existe
if [ ! -f "$OUTPUT_FILE" ]; then
echo '{"total_unicos": 0, "visitas": []}' > "$OUTPUT_FILE"
fi
zgrep "$TARGET_URL" $LOG_PATH | awk -F'"' '{
split($1, a, " ");
ip = a[1]; fecha = substr(a[4], 2, 11); ua = $6;
print ip "|" fecha "|" ua
}' | sort -u > temp_agents.txt
while IFS="|" read -r ip fecha ua; do
if ! jq -e --arg ua "$ua" --arg date "$fecha" '.visitas[] | select(.user_agent == $ua and .fecha == $date)' "$OUTPUT_FILE" > /dev/null; then
jq --arg ip "$ip" --arg date "$fecha" --arg ua "$ua" \
'.visitas += [{"ip": $ip, "fecha": $date, "user_agent": $ua}] | .total_unicos = (.visitas | map(.user_agent) | unique | length)' \
"$OUTPUT_FILE" > "$OUTPUT_FILE.tmp" && mv "$OUTPUT_FILE.tmp" "$OUTPUT_FILE"
fi
done < temp_agents.txt
# 2. Generar datos para Gnuplot (Frecuencia por fecha)
# Extraemos del JSON: "Fecha Cuenta"
jq -r '.visitas[].fecha' "$OUTPUT_FILE" | sort | uniq -c | awk '{print $2, $1}' > datos_grafica.dat
# 3. Generar la gráfica con Gnuplot
echo "Generando gráfica con Gnuplot..."
gnuplot <<EOF
set terminal pngcairo size 800,600 font "sans,10"
set output 'frecuencia_visitas.png'
set title "Frecuencia de Visitas a $TARGET_URL"
set xlabel "Fecha"
set ylabel "Visitas"
set style fill solid
set boxwidth 0.5
set xtics rotate by -45
plot "datos_grafica.dat" using 2:xtic(1) with boxes title "Visitas por día"
EOF
# Limpieza
rm temp_agents.txt datos_grafica.dat
echo "Proceso completado. Gráfica guardada en frecuencia_visitas.png"