Skip to content

Instantly share code, notes, and snippets.

@ljamel
Created January 31, 2026 17:53
Show Gist options
  • Select an option

  • Save ljamel/3eeeaba890fbaddb8520de889acc0e30 to your computer and use it in GitHub Desktop.

Select an option

Save ljamel/3eeeaba890fbaddb8520de889acc0e30 to your computer and use it in GitHub Desktop.
#!/bin/bash
# analititycs for server lamp with apache
LOGFILE="/var/log/apache2/access.log"
awk '
function mon2num(m) {
return (m=="Jan")?1:(m=="Feb")?2:(m=="Mar")?3:(m=="Apr")?4:
(m=="May")?5:(m=="Jun")?6:(m=="Jul")?7:(m=="Aug")?8:
(m=="Sep")?9:(m=="Oct")?10:(m=="Nov")?11:(m=="Dec")?12:0
}
$6 == "\"GET" && $7 == "/" && $9 == 200 {
gsub(/\[/, "", $4)
split($4, p, ":")
split(p[1], d, "/")
day = d[1]
month = mon2num(d[2])
year = d[3]
sortkey = sprintf("%04d%02d%02d", year, month, day)
date = p[1]
ip = $1
hits[date, ip]++
keydate[date] = sortkey
}
END {
printf "%-12s %-6s %s\n", "Date", "Hits", "Graph"
print "------------------------------------------------------------"
# total par jour (filtré hits > 1)
for (k in hits) {
split(k, a, SUBSEP)
date = a[1]
h = hits[k]
if (h > 1)
total[date] += h
}
# tri chronologique
n = asorti(keydate, dates, "@val_num_asc")
for (i = 1; i <= n; i++) {
date = dates[i]
h = total[date]
bar=""
for (j = 0; j < h; j++) bar = bar "█"
printf "%-12s %-6d %s\n", date, h, bar
}
}
' "$LOGFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment